]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.10.10-201309052118.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.10.10-201309052118.patch
CommitLineData
0c61329e
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 b119684..13ac256 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 988c812..63c7d70 100644
7652--- a/arch/powerpc/include/asm/page.h
7653+++ b/arch/powerpc/include/asm/page.h
7654@@ -220,8 +220,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@@ -249,6 +250,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 1f34e92..c97b98f 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/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42119index 6a8405d..0bd1c7e 100644
42120--- a/drivers/leds/leds-clevo-mail.c
42121+++ b/drivers/leds/leds-clevo-mail.c
42122@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42123 * detected as working, but in reality it is not) as low as
42124 * possible.
42125 */
42126-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
42127+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
42128 {
42129 .callback = clevo_mail_led_dmi_callback,
42130 .ident = "Clevo D410J",
42131diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42132index 64e204e..c6bf189 100644
42133--- a/drivers/leds/leds-ss4200.c
42134+++ b/drivers/leds/leds-ss4200.c
42135@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42136 * detected as working, but in reality it is not) as low as
42137 * possible.
42138 */
42139-static struct dmi_system_id __initdata nas_led_whitelist[] = {
42140+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
42141 {
42142 .callback = ss4200_led_dmi_callback,
42143 .ident = "Intel SS4200-E",
42144diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42145index 0bf1e4e..b4bf44e 100644
42146--- a/drivers/lguest/core.c
42147+++ b/drivers/lguest/core.c
42148@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42149 * The end address needs +1 because __get_vm_area allocates an
42150 * extra guard page, so we need space for that.
42151 */
42152+
42153+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42154+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42155+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42156+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42157+#else
42158 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42159 VM_ALLOC, switcher_addr, switcher_addr
42160 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42161+#endif
42162+
42163 if (!switcher_vma) {
42164 err = -ENOMEM;
42165 printk("lguest: could not map switcher pages high\n");
42166@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42167 * Now the Switcher is mapped at the right address, we can't fail!
42168 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42169 */
42170- memcpy(switcher_vma->addr, start_switcher_text,
42171+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42172 end_switcher_text - start_switcher_text);
42173
42174 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42175diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42176index 5b9ac32..2ef4f26 100644
42177--- a/drivers/lguest/page_tables.c
42178+++ b/drivers/lguest/page_tables.c
42179@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42180 /*:*/
42181
42182 #ifdef CONFIG_X86_PAE
42183-static void release_pmd(pmd_t *spmd)
42184+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42185 {
42186 /* If the entry's not present, there's nothing to release. */
42187 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42188diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42189index f0a3347..f6608b2 100644
42190--- a/drivers/lguest/x86/core.c
42191+++ b/drivers/lguest/x86/core.c
42192@@ -59,7 +59,7 @@ static struct {
42193 /* Offset from where switcher.S was compiled to where we've copied it */
42194 static unsigned long switcher_offset(void)
42195 {
42196- return switcher_addr - (unsigned long)start_switcher_text;
42197+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42198 }
42199
42200 /* This cpu's struct lguest_pages (after the Switcher text page) */
42201@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42202 * These copies are pretty cheap, so we do them unconditionally: */
42203 /* Save the current Host top-level page directory.
42204 */
42205+
42206+#ifdef CONFIG_PAX_PER_CPU_PGD
42207+ pages->state.host_cr3 = read_cr3();
42208+#else
42209 pages->state.host_cr3 = __pa(current->mm->pgd);
42210+#endif
42211+
42212 /*
42213 * Set up the Guest's page tables to see this CPU's pages (and no
42214 * other CPU's pages).
42215@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42216 * compiled-in switcher code and the high-mapped copy we just made.
42217 */
42218 for (i = 0; i < IDT_ENTRIES; i++)
42219- default_idt_entries[i] += switcher_offset();
42220+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42221
42222 /*
42223 * Set up the Switcher's per-cpu areas.
42224@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42225 * it will be undisturbed when we switch. To change %cs and jump we
42226 * need this structure to feed to Intel's "lcall" instruction.
42227 */
42228- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42229+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42230 lguest_entry.segment = LGUEST_CS;
42231
42232 /*
42233diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42234index 40634b0..4f5855e 100644
42235--- a/drivers/lguest/x86/switcher_32.S
42236+++ b/drivers/lguest/x86/switcher_32.S
42237@@ -87,6 +87,7 @@
42238 #include <asm/page.h>
42239 #include <asm/segment.h>
42240 #include <asm/lguest.h>
42241+#include <asm/processor-flags.h>
42242
42243 // We mark the start of the code to copy
42244 // It's placed in .text tho it's never run here
42245@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42246 // Changes type when we load it: damn Intel!
42247 // For after we switch over our page tables
42248 // That entry will be read-only: we'd crash.
42249+
42250+#ifdef CONFIG_PAX_KERNEXEC
42251+ mov %cr0, %edx
42252+ xor $X86_CR0_WP, %edx
42253+ mov %edx, %cr0
42254+#endif
42255+
42256 movl $(GDT_ENTRY_TSS*8), %edx
42257 ltr %dx
42258
42259@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42260 // Let's clear it again for our return.
42261 // The GDT descriptor of the Host
42262 // Points to the table after two "size" bytes
42263- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42264+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42265 // Clear "used" from type field (byte 5, bit 2)
42266- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42267+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42268+
42269+#ifdef CONFIG_PAX_KERNEXEC
42270+ mov %cr0, %eax
42271+ xor $X86_CR0_WP, %eax
42272+ mov %eax, %cr0
42273+#endif
42274
42275 // Once our page table's switched, the Guest is live!
42276 // The Host fades as we run this final step.
42277@@ -295,13 +309,12 @@ deliver_to_host:
42278 // I consulted gcc, and it gave
42279 // These instructions, which I gladly credit:
42280 leal (%edx,%ebx,8), %eax
42281- movzwl (%eax),%edx
42282- movl 4(%eax), %eax
42283- xorw %ax, %ax
42284- orl %eax, %edx
42285+ movl 4(%eax), %edx
42286+ movw (%eax), %dx
42287 // Now the address of the handler's in %edx
42288 // We call it now: its "iret" drops us home.
42289- jmp *%edx
42290+ ljmp $__KERNEL_CS, $1f
42291+1: jmp *%edx
42292
42293 // Every interrupt can come to us here
42294 // But we must truly tell each apart.
42295diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42296index 0003992..854bbce 100644
42297--- a/drivers/md/bcache/closure.h
42298+++ b/drivers/md/bcache/closure.h
42299@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42300 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42301 struct workqueue_struct *wq)
42302 {
42303- BUG_ON(object_is_on_stack(cl));
42304+ BUG_ON(object_starts_on_stack(cl));
42305 closure_set_ip(cl);
42306 cl->fn = fn;
42307 cl->wq = wq;
42308diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42309index b4713ce..b30139b 100644
42310--- a/drivers/md/bcache/super.c
42311+++ b/drivers/md/bcache/super.c
42312@@ -1603,7 +1603,7 @@ err_unlock_gc:
42313 err:
42314 closure_sync(&op.cl);
42315 /* XXX: test this, it's broken */
42316- bch_cache_set_error(c, err);
42317+ bch_cache_set_error(c, "%s", err);
42318 }
42319
42320 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42321diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42322index 5a2c754..0fa55db 100644
42323--- a/drivers/md/bitmap.c
42324+++ b/drivers/md/bitmap.c
42325@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42326 chunk_kb ? "KB" : "B");
42327 if (bitmap->storage.file) {
42328 seq_printf(seq, ", file: ");
42329- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42330+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42331 }
42332
42333 seq_printf(seq, "\n");
42334diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42335index 81a79b7..87a0f73 100644
42336--- a/drivers/md/dm-ioctl.c
42337+++ b/drivers/md/dm-ioctl.c
42338@@ -1697,7 +1697,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42339 cmd == DM_LIST_VERSIONS_CMD)
42340 return 0;
42341
42342- if ((cmd == DM_DEV_CREATE_CMD)) {
42343+ if (cmd == DM_DEV_CREATE_CMD) {
42344 if (!*param->name) {
42345 DMWARN("name not supplied when creating device");
42346 return -EINVAL;
42347diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42348index 699b5be..eac0a15 100644
42349--- a/drivers/md/dm-raid1.c
42350+++ b/drivers/md/dm-raid1.c
42351@@ -40,7 +40,7 @@ enum dm_raid1_error {
42352
42353 struct mirror {
42354 struct mirror_set *ms;
42355- atomic_t error_count;
42356+ atomic_unchecked_t error_count;
42357 unsigned long error_type;
42358 struct dm_dev *dev;
42359 sector_t offset;
42360@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42361 struct mirror *m;
42362
42363 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42364- if (!atomic_read(&m->error_count))
42365+ if (!atomic_read_unchecked(&m->error_count))
42366 return m;
42367
42368 return NULL;
42369@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42370 * simple way to tell if a device has encountered
42371 * errors.
42372 */
42373- atomic_inc(&m->error_count);
42374+ atomic_inc_unchecked(&m->error_count);
42375
42376 if (test_and_set_bit(error_type, &m->error_type))
42377 return;
42378@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42379 struct mirror *m = get_default_mirror(ms);
42380
42381 do {
42382- if (likely(!atomic_read(&m->error_count)))
42383+ if (likely(!atomic_read_unchecked(&m->error_count)))
42384 return m;
42385
42386 if (m-- == ms->mirror)
42387@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42388 {
42389 struct mirror *default_mirror = get_default_mirror(m->ms);
42390
42391- return !atomic_read(&default_mirror->error_count);
42392+ return !atomic_read_unchecked(&default_mirror->error_count);
42393 }
42394
42395 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42396@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42397 */
42398 if (likely(region_in_sync(ms, region, 1)))
42399 m = choose_mirror(ms, bio->bi_sector);
42400- else if (m && atomic_read(&m->error_count))
42401+ else if (m && atomic_read_unchecked(&m->error_count))
42402 m = NULL;
42403
42404 if (likely(m))
42405@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42406 }
42407
42408 ms->mirror[mirror].ms = ms;
42409- atomic_set(&(ms->mirror[mirror].error_count), 0);
42410+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42411 ms->mirror[mirror].error_type = 0;
42412 ms->mirror[mirror].offset = offset;
42413
42414@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42415 */
42416 static char device_status_char(struct mirror *m)
42417 {
42418- if (!atomic_read(&(m->error_count)))
42419+ if (!atomic_read_unchecked(&(m->error_count)))
42420 return 'A';
42421
42422 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42423diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42424index d907ca6..cfb8384 100644
42425--- a/drivers/md/dm-stripe.c
42426+++ b/drivers/md/dm-stripe.c
42427@@ -20,7 +20,7 @@ struct stripe {
42428 struct dm_dev *dev;
42429 sector_t physical_start;
42430
42431- atomic_t error_count;
42432+ atomic_unchecked_t error_count;
42433 };
42434
42435 struct stripe_c {
42436@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42437 kfree(sc);
42438 return r;
42439 }
42440- atomic_set(&(sc->stripe[i].error_count), 0);
42441+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42442 }
42443
42444 ti->private = sc;
42445@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42446 DMEMIT("%d ", sc->stripes);
42447 for (i = 0; i < sc->stripes; i++) {
42448 DMEMIT("%s ", sc->stripe[i].dev->name);
42449- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42450+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42451 'D' : 'A';
42452 }
42453 buffer[i] = '\0';
42454@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42455 */
42456 for (i = 0; i < sc->stripes; i++)
42457 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42458- atomic_inc(&(sc->stripe[i].error_count));
42459- if (atomic_read(&(sc->stripe[i].error_count)) <
42460+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42461+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42462 DM_IO_ERROR_THRESHOLD)
42463 schedule_work(&sc->trigger_event);
42464 }
42465diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42466index 1ff252a..ee384c1 100644
42467--- a/drivers/md/dm-table.c
42468+++ b/drivers/md/dm-table.c
42469@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42470 if (!dev_size)
42471 return 0;
42472
42473- if ((start >= dev_size) || (start + len > dev_size)) {
42474+ if ((start >= dev_size) || (len > dev_size - start)) {
42475 DMWARN("%s: %s too small for target: "
42476 "start=%llu, len=%llu, dev_size=%llu",
42477 dm_device_name(ti->table->md), bdevname(bdev, b),
42478diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42479index 60bce43..9b997d0 100644
42480--- a/drivers/md/dm-thin-metadata.c
42481+++ b/drivers/md/dm-thin-metadata.c
42482@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42483 {
42484 pmd->info.tm = pmd->tm;
42485 pmd->info.levels = 2;
42486- pmd->info.value_type.context = pmd->data_sm;
42487+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42488 pmd->info.value_type.size = sizeof(__le64);
42489 pmd->info.value_type.inc = data_block_inc;
42490 pmd->info.value_type.dec = data_block_dec;
42491@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42492
42493 pmd->bl_info.tm = pmd->tm;
42494 pmd->bl_info.levels = 1;
42495- pmd->bl_info.value_type.context = pmd->data_sm;
42496+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42497 pmd->bl_info.value_type.size = sizeof(__le64);
42498 pmd->bl_info.value_type.inc = data_block_inc;
42499 pmd->bl_info.value_type.dec = data_block_dec;
42500diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42501index 33f2010..23fb84c 100644
42502--- a/drivers/md/dm.c
42503+++ b/drivers/md/dm.c
42504@@ -169,9 +169,9 @@ struct mapped_device {
42505 /*
42506 * Event handling.
42507 */
42508- atomic_t event_nr;
42509+ atomic_unchecked_t event_nr;
42510 wait_queue_head_t eventq;
42511- atomic_t uevent_seq;
42512+ atomic_unchecked_t uevent_seq;
42513 struct list_head uevent_list;
42514 spinlock_t uevent_lock; /* Protect access to uevent_list */
42515
42516@@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
42517 rwlock_init(&md->map_lock);
42518 atomic_set(&md->holders, 1);
42519 atomic_set(&md->open_count, 0);
42520- atomic_set(&md->event_nr, 0);
42521- atomic_set(&md->uevent_seq, 0);
42522+ atomic_set_unchecked(&md->event_nr, 0);
42523+ atomic_set_unchecked(&md->uevent_seq, 0);
42524 INIT_LIST_HEAD(&md->uevent_list);
42525 spin_lock_init(&md->uevent_lock);
42526
42527@@ -2033,7 +2033,7 @@ static void event_callback(void *context)
42528
42529 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42530
42531- atomic_inc(&md->event_nr);
42532+ atomic_inc_unchecked(&md->event_nr);
42533 wake_up(&md->eventq);
42534 }
42535
42536@@ -2690,18 +2690,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42537
42538 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42539 {
42540- return atomic_add_return(1, &md->uevent_seq);
42541+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42542 }
42543
42544 uint32_t dm_get_event_nr(struct mapped_device *md)
42545 {
42546- return atomic_read(&md->event_nr);
42547+ return atomic_read_unchecked(&md->event_nr);
42548 }
42549
42550 int dm_wait_event(struct mapped_device *md, int event_nr)
42551 {
42552 return wait_event_interruptible(md->eventq,
42553- (event_nr != atomic_read(&md->event_nr)));
42554+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42555 }
42556
42557 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42558diff --git a/drivers/md/md.c b/drivers/md/md.c
42559index 51f0345..c77810e 100644
42560--- a/drivers/md/md.c
42561+++ b/drivers/md/md.c
42562@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42563 * start build, activate spare
42564 */
42565 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42566-static atomic_t md_event_count;
42567+static atomic_unchecked_t md_event_count;
42568 void md_new_event(struct mddev *mddev)
42569 {
42570- atomic_inc(&md_event_count);
42571+ atomic_inc_unchecked(&md_event_count);
42572 wake_up(&md_event_waiters);
42573 }
42574 EXPORT_SYMBOL_GPL(md_new_event);
42575@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42576 */
42577 static void md_new_event_inintr(struct mddev *mddev)
42578 {
42579- atomic_inc(&md_event_count);
42580+ atomic_inc_unchecked(&md_event_count);
42581 wake_up(&md_event_waiters);
42582 }
42583
42584@@ -1501,7 +1501,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42585 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42586 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42587 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42588- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42589+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42590
42591 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42592 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42593@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42594 else
42595 sb->resync_offset = cpu_to_le64(0);
42596
42597- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42598+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42599
42600 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42601 sb->size = cpu_to_le64(mddev->dev_sectors);
42602@@ -2750,7 +2750,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42603 static ssize_t
42604 errors_show(struct md_rdev *rdev, char *page)
42605 {
42606- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42607+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42608 }
42609
42610 static ssize_t
42611@@ -2759,7 +2759,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42612 char *e;
42613 unsigned long n = simple_strtoul(buf, &e, 10);
42614 if (*buf && (*e == 0 || *e == '\n')) {
42615- atomic_set(&rdev->corrected_errors, n);
42616+ atomic_set_unchecked(&rdev->corrected_errors, n);
42617 return len;
42618 }
42619 return -EINVAL;
42620@@ -3207,8 +3207,8 @@ int md_rdev_init(struct md_rdev *rdev)
42621 rdev->sb_loaded = 0;
42622 rdev->bb_page = NULL;
42623 atomic_set(&rdev->nr_pending, 0);
42624- atomic_set(&rdev->read_errors, 0);
42625- atomic_set(&rdev->corrected_errors, 0);
42626+ atomic_set_unchecked(&rdev->read_errors, 0);
42627+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42628
42629 INIT_LIST_HEAD(&rdev->same_set);
42630 init_waitqueue_head(&rdev->blocked_wait);
42631@@ -7009,7 +7009,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42632
42633 spin_unlock(&pers_lock);
42634 seq_printf(seq, "\n");
42635- seq->poll_event = atomic_read(&md_event_count);
42636+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42637 return 0;
42638 }
42639 if (v == (void*)2) {
42640@@ -7112,7 +7112,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42641 return error;
42642
42643 seq = file->private_data;
42644- seq->poll_event = atomic_read(&md_event_count);
42645+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42646 return error;
42647 }
42648
42649@@ -7126,7 +7126,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42650 /* always allow read */
42651 mask = POLLIN | POLLRDNORM;
42652
42653- if (seq->poll_event != atomic_read(&md_event_count))
42654+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42655 mask |= POLLERR | POLLPRI;
42656 return mask;
42657 }
42658@@ -7170,7 +7170,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42659 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42660 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42661 (int)part_stat_read(&disk->part0, sectors[1]) -
42662- atomic_read(&disk->sync_io);
42663+ atomic_read_unchecked(&disk->sync_io);
42664 /* sync IO will cause sync_io to increase before the disk_stats
42665 * as sync_io is counted when a request starts, and
42666 * disk_stats is counted when it completes.
42667diff --git a/drivers/md/md.h b/drivers/md/md.h
42668index 653f992b6..6af6c40 100644
42669--- a/drivers/md/md.h
42670+++ b/drivers/md/md.h
42671@@ -94,13 +94,13 @@ struct md_rdev {
42672 * only maintained for arrays that
42673 * support hot removal
42674 */
42675- atomic_t read_errors; /* number of consecutive read errors that
42676+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42677 * we have tried to ignore.
42678 */
42679 struct timespec last_read_error; /* monotonic time since our
42680 * last read error
42681 */
42682- atomic_t corrected_errors; /* number of corrected read errors,
42683+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42684 * for reporting to userspace and storing
42685 * in superblock.
42686 */
42687@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42688
42689 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42690 {
42691- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42692+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42693 }
42694
42695 struct md_personality
42696diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42697index 3e6d115..ffecdeb 100644
42698--- a/drivers/md/persistent-data/dm-space-map.h
42699+++ b/drivers/md/persistent-data/dm-space-map.h
42700@@ -71,6 +71,7 @@ struct dm_space_map {
42701 dm_sm_threshold_fn fn,
42702 void *context);
42703 };
42704+typedef struct dm_space_map __no_const dm_space_map_no_const;
42705
42706 /*----------------------------------------------------------------*/
42707
42708diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42709index 6f48244..7d29145 100644
42710--- a/drivers/md/raid1.c
42711+++ b/drivers/md/raid1.c
42712@@ -1822,7 +1822,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42713 if (r1_sync_page_io(rdev, sect, s,
42714 bio->bi_io_vec[idx].bv_page,
42715 READ) != 0)
42716- atomic_add(s, &rdev->corrected_errors);
42717+ atomic_add_unchecked(s, &rdev->corrected_errors);
42718 }
42719 sectors -= s;
42720 sect += s;
42721@@ -2049,7 +2049,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42722 test_bit(In_sync, &rdev->flags)) {
42723 if (r1_sync_page_io(rdev, sect, s,
42724 conf->tmppage, READ)) {
42725- atomic_add(s, &rdev->corrected_errors);
42726+ atomic_add_unchecked(s, &rdev->corrected_errors);
42727 printk(KERN_INFO
42728 "md/raid1:%s: read error corrected "
42729 "(%d sectors at %llu on %s)\n",
42730diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42731index 081bb33..3c4b287 100644
42732--- a/drivers/md/raid10.c
42733+++ b/drivers/md/raid10.c
42734@@ -1940,7 +1940,7 @@ static void end_sync_read(struct bio *bio, int error)
42735 /* The write handler will notice the lack of
42736 * R10BIO_Uptodate and record any errors etc
42737 */
42738- atomic_add(r10_bio->sectors,
42739+ atomic_add_unchecked(r10_bio->sectors,
42740 &conf->mirrors[d].rdev->corrected_errors);
42741
42742 /* for reconstruct, we always reschedule after a read.
42743@@ -2298,7 +2298,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42744 {
42745 struct timespec cur_time_mon;
42746 unsigned long hours_since_last;
42747- unsigned int read_errors = atomic_read(&rdev->read_errors);
42748+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42749
42750 ktime_get_ts(&cur_time_mon);
42751
42752@@ -2320,9 +2320,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42753 * overflowing the shift of read_errors by hours_since_last.
42754 */
42755 if (hours_since_last >= 8 * sizeof(read_errors))
42756- atomic_set(&rdev->read_errors, 0);
42757+ atomic_set_unchecked(&rdev->read_errors, 0);
42758 else
42759- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42760+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42761 }
42762
42763 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42764@@ -2376,8 +2376,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42765 return;
42766
42767 check_decay_read_errors(mddev, rdev);
42768- atomic_inc(&rdev->read_errors);
42769- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42770+ atomic_inc_unchecked(&rdev->read_errors);
42771+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42772 char b[BDEVNAME_SIZE];
42773 bdevname(rdev->bdev, b);
42774
42775@@ -2385,7 +2385,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42776 "md/raid10:%s: %s: Raid device exceeded "
42777 "read_error threshold [cur %d:max %d]\n",
42778 mdname(mddev), b,
42779- atomic_read(&rdev->read_errors), max_read_errors);
42780+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42781 printk(KERN_NOTICE
42782 "md/raid10:%s: %s: Failing raid device\n",
42783 mdname(mddev), b);
42784@@ -2540,7 +2540,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42785 sect +
42786 choose_data_offset(r10_bio, rdev)),
42787 bdevname(rdev->bdev, b));
42788- atomic_add(s, &rdev->corrected_errors);
42789+ atomic_add_unchecked(s, &rdev->corrected_errors);
42790 }
42791
42792 rdev_dec_pending(rdev, mddev);
42793diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42794index a35b846..e295c6d 100644
42795--- a/drivers/md/raid5.c
42796+++ b/drivers/md/raid5.c
42797@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42798 mdname(conf->mddev), STRIPE_SECTORS,
42799 (unsigned long long)s,
42800 bdevname(rdev->bdev, b));
42801- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42802+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42803 clear_bit(R5_ReadError, &sh->dev[i].flags);
42804 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42805 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42806 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42807
42808- if (atomic_read(&rdev->read_errors))
42809- atomic_set(&rdev->read_errors, 0);
42810+ if (atomic_read_unchecked(&rdev->read_errors))
42811+ atomic_set_unchecked(&rdev->read_errors, 0);
42812 } else {
42813 const char *bdn = bdevname(rdev->bdev, b);
42814 int retry = 0;
42815 int set_bad = 0;
42816
42817 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42818- atomic_inc(&rdev->read_errors);
42819+ atomic_inc_unchecked(&rdev->read_errors);
42820 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42821 printk_ratelimited(
42822 KERN_WARNING
42823@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42824 mdname(conf->mddev),
42825 (unsigned long long)s,
42826 bdn);
42827- } else if (atomic_read(&rdev->read_errors)
42828+ } else if (atomic_read_unchecked(&rdev->read_errors)
42829 > conf->max_nr_stripes)
42830 printk(KERN_WARNING
42831 "md/raid:%s: Too many read errors, failing device %s.\n",
42832diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42833index 401ef64..836e563 100644
42834--- a/drivers/media/dvb-core/dvbdev.c
42835+++ b/drivers/media/dvb-core/dvbdev.c
42836@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42837 const struct dvb_device *template, void *priv, int type)
42838 {
42839 struct dvb_device *dvbdev;
42840- struct file_operations *dvbdevfops;
42841+ file_operations_no_const *dvbdevfops;
42842 struct device *clsdev;
42843 int minor;
42844 int id;
42845diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42846index 9b6c3bb..baeb5c7 100644
42847--- a/drivers/media/dvb-frontends/dib3000.h
42848+++ b/drivers/media/dvb-frontends/dib3000.h
42849@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42850 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42851 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42852 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42853-};
42854+} __no_const;
42855
42856 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42857 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42858diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42859index c7a9be1..683f6f8 100644
42860--- a/drivers/media/pci/cx88/cx88-video.c
42861+++ b/drivers/media/pci/cx88/cx88-video.c
42862@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42863
42864 /* ------------------------------------------------------------------ */
42865
42866-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42867-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42868-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42869+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42870+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42871+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42872
42873 module_param_array(video_nr, int, NULL, 0444);
42874 module_param_array(vbi_nr, int, NULL, 0444);
42875diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42876index 07b8460..e6d7265 100644
42877--- a/drivers/media/pci/ivtv/ivtv-driver.c
42878+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42879@@ -84,7 +84,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42880 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42881
42882 /* ivtv instance counter */
42883-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42884+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42885
42886 /* Parameter declarations */
42887 static int cardtype[IVTV_MAX_CARDS];
42888diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42889index d338b19..aae4f9e 100644
42890--- a/drivers/media/platform/omap/omap_vout.c
42891+++ b/drivers/media/platform/omap/omap_vout.c
42892@@ -63,7 +63,6 @@ enum omap_vout_channels {
42893 OMAP_VIDEO2,
42894 };
42895
42896-static struct videobuf_queue_ops video_vbq_ops;
42897 /* Variables configurable through module params*/
42898 static u32 video1_numbuffers = 3;
42899 static u32 video2_numbuffers = 3;
42900@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
42901 {
42902 struct videobuf_queue *q;
42903 struct omap_vout_device *vout = NULL;
42904+ static struct videobuf_queue_ops video_vbq_ops = {
42905+ .buf_setup = omap_vout_buffer_setup,
42906+ .buf_prepare = omap_vout_buffer_prepare,
42907+ .buf_release = omap_vout_buffer_release,
42908+ .buf_queue = omap_vout_buffer_queue,
42909+ };
42910
42911 vout = video_drvdata(file);
42912 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42913@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
42914 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42915
42916 q = &vout->vbq;
42917- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42918- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42919- video_vbq_ops.buf_release = omap_vout_buffer_release;
42920- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42921 spin_lock_init(&vout->vbq_lock);
42922
42923 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42924diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42925index 04e6490..2df65bf 100644
42926--- a/drivers/media/platform/s5p-tv/mixer.h
42927+++ b/drivers/media/platform/s5p-tv/mixer.h
42928@@ -156,7 +156,7 @@ struct mxr_layer {
42929 /** layer index (unique identifier) */
42930 int idx;
42931 /** callbacks for layer methods */
42932- struct mxr_layer_ops ops;
42933+ struct mxr_layer_ops *ops;
42934 /** format array */
42935 const struct mxr_format **fmt_array;
42936 /** size of format array */
42937diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42938index b93a21f..2535195 100644
42939--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42940+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42941@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42942 {
42943 struct mxr_layer *layer;
42944 int ret;
42945- struct mxr_layer_ops ops = {
42946+ static struct mxr_layer_ops ops = {
42947 .release = mxr_graph_layer_release,
42948 .buffer_set = mxr_graph_buffer_set,
42949 .stream_set = mxr_graph_stream_set,
42950diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42951index b713403..53cb5ad 100644
42952--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42953+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42954@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42955 layer->update_buf = next;
42956 }
42957
42958- layer->ops.buffer_set(layer, layer->update_buf);
42959+ layer->ops->buffer_set(layer, layer->update_buf);
42960
42961 if (done && done != layer->shadow_buf)
42962 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42963diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42964index ef0efdf..8c78eb6 100644
42965--- a/drivers/media/platform/s5p-tv/mixer_video.c
42966+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42967@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42968 layer->geo.src.height = layer->geo.src.full_height;
42969
42970 mxr_geometry_dump(mdev, &layer->geo);
42971- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42972+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42973 mxr_geometry_dump(mdev, &layer->geo);
42974 }
42975
42976@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42977 layer->geo.dst.full_width = mbus_fmt.width;
42978 layer->geo.dst.full_height = mbus_fmt.height;
42979 layer->geo.dst.field = mbus_fmt.field;
42980- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42981+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42982
42983 mxr_geometry_dump(mdev, &layer->geo);
42984 }
42985@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42986 /* set source size to highest accepted value */
42987 geo->src.full_width = max(geo->dst.full_width, pix->width);
42988 geo->src.full_height = max(geo->dst.full_height, pix->height);
42989- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42990+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42991 mxr_geometry_dump(mdev, &layer->geo);
42992 /* set cropping to total visible screen */
42993 geo->src.width = pix->width;
42994@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42995 geo->src.x_offset = 0;
42996 geo->src.y_offset = 0;
42997 /* assure consistency of geometry */
42998- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42999+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43000 mxr_geometry_dump(mdev, &layer->geo);
43001 /* set full size to lowest possible value */
43002 geo->src.full_width = 0;
43003 geo->src.full_height = 0;
43004- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43005+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43006 mxr_geometry_dump(mdev, &layer->geo);
43007
43008 /* returning results */
43009@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43010 target->width = s->r.width;
43011 target->height = s->r.height;
43012
43013- layer->ops.fix_geometry(layer, stage, s->flags);
43014+ layer->ops->fix_geometry(layer, stage, s->flags);
43015
43016 /* retrieve update selection rectangle */
43017 res.left = target->x_offset;
43018@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43019 mxr_output_get(mdev);
43020
43021 mxr_layer_update_output(layer);
43022- layer->ops.format_set(layer);
43023+ layer->ops->format_set(layer);
43024 /* enabling layer in hardware */
43025 spin_lock_irqsave(&layer->enq_slock, flags);
43026 layer->state = MXR_LAYER_STREAMING;
43027 spin_unlock_irqrestore(&layer->enq_slock, flags);
43028
43029- layer->ops.stream_set(layer, MXR_ENABLE);
43030+ layer->ops->stream_set(layer, MXR_ENABLE);
43031 mxr_streamer_get(mdev);
43032
43033 return 0;
43034@@ -1030,7 +1030,7 @@ static int stop_streaming(struct vb2_queue *vq)
43035 spin_unlock_irqrestore(&layer->enq_slock, flags);
43036
43037 /* disabling layer in hardware */
43038- layer->ops.stream_set(layer, MXR_DISABLE);
43039+ layer->ops->stream_set(layer, MXR_DISABLE);
43040 /* remove one streamer */
43041 mxr_streamer_put(mdev);
43042 /* allow changes in output configuration */
43043@@ -1069,8 +1069,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43044
43045 void mxr_layer_release(struct mxr_layer *layer)
43046 {
43047- if (layer->ops.release)
43048- layer->ops.release(layer);
43049+ if (layer->ops->release)
43050+ layer->ops->release(layer);
43051 }
43052
43053 void mxr_base_layer_release(struct mxr_layer *layer)
43054@@ -1096,7 +1096,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43055
43056 layer->mdev = mdev;
43057 layer->idx = idx;
43058- layer->ops = *ops;
43059+ layer->ops = ops;
43060
43061 spin_lock_init(&layer->enq_slock);
43062 INIT_LIST_HEAD(&layer->enq_list);
43063diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43064index 3d13a63..da31bf1 100644
43065--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43066+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43067@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43068 {
43069 struct mxr_layer *layer;
43070 int ret;
43071- struct mxr_layer_ops ops = {
43072+ static struct mxr_layer_ops ops = {
43073 .release = mxr_vp_layer_release,
43074 .buffer_set = mxr_vp_buffer_set,
43075 .stream_set = mxr_vp_stream_set,
43076diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43077index 545c04c..a14bded 100644
43078--- a/drivers/media/radio/radio-cadet.c
43079+++ b/drivers/media/radio/radio-cadet.c
43080@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43081 unsigned char readbuf[RDS_BUFFER];
43082 int i = 0;
43083
43084+ if (count > RDS_BUFFER)
43085+ return -EFAULT;
43086 mutex_lock(&dev->lock);
43087 if (dev->rdsstat == 0)
43088 cadet_start_rds(dev);
43089@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43090 while (i < count && dev->rdsin != dev->rdsout)
43091 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43092
43093- if (i && copy_to_user(data, readbuf, i))
43094+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43095 i = -EFAULT;
43096 unlock:
43097 mutex_unlock(&dev->lock);
43098diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43099index bd4d3a7..ffc0b9d 100644
43100--- a/drivers/media/radio/radio-maxiradio.c
43101+++ b/drivers/media/radio/radio-maxiradio.c
43102@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43103 /* TEA5757 pin mappings */
43104 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43105
43106-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43107+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43108
43109 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43110 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43111diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43112index 8fa18ab..caee70f 100644
43113--- a/drivers/media/radio/radio-shark.c
43114+++ b/drivers/media/radio/radio-shark.c
43115@@ -79,7 +79,7 @@ struct shark_device {
43116 u32 last_val;
43117 };
43118
43119-static atomic_t shark_instance = ATOMIC_INIT(0);
43120+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43121
43122 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43123 {
43124diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43125index 9fb6697..f167415 100644
43126--- a/drivers/media/radio/radio-shark2.c
43127+++ b/drivers/media/radio/radio-shark2.c
43128@@ -74,7 +74,7 @@ struct shark_device {
43129 u8 *transfer_buffer;
43130 };
43131
43132-static atomic_t shark_instance = ATOMIC_INIT(0);
43133+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43134
43135 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43136 {
43137diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43138index 9dc8baf..796d52f 100644
43139--- a/drivers/media/radio/radio-si476x.c
43140+++ b/drivers/media/radio/radio-si476x.c
43141@@ -1456,7 +1456,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43142 struct si476x_radio *radio;
43143 struct v4l2_ctrl *ctrl;
43144
43145- static atomic_t instance = ATOMIC_INIT(0);
43146+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43147
43148 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43149 if (!radio)
43150diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43151index 1cf382a..c22998c 100644
43152--- a/drivers/media/rc/rc-main.c
43153+++ b/drivers/media/rc/rc-main.c
43154@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43155 int rc_register_device(struct rc_dev *dev)
43156 {
43157 static bool raw_init = false; /* raw decoders loaded? */
43158- static atomic_t devno = ATOMIC_INIT(0);
43159+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43160 struct rc_map *rc_map;
43161 const char *path;
43162 int rc;
43163@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
43164 */
43165 mutex_lock(&dev->lock);
43166
43167- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43168+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43169 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43170 dev_set_drvdata(&dev->dev, dev);
43171 rc = device_add(&dev->dev);
43172diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43173index 3940bb0..fb3952a 100644
43174--- a/drivers/media/usb/dvb-usb/cxusb.c
43175+++ b/drivers/media/usb/dvb-usb/cxusb.c
43176@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43177
43178 struct dib0700_adapter_state {
43179 int (*set_param_save) (struct dvb_frontend *);
43180-};
43181+} __no_const;
43182
43183 static int dib7070_set_param_override(struct dvb_frontend *fe)
43184 {
43185diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43186index 6e237b6..dc25556 100644
43187--- a/drivers/media/usb/dvb-usb/dw2102.c
43188+++ b/drivers/media/usb/dvb-usb/dw2102.c
43189@@ -118,7 +118,7 @@ struct su3000_state {
43190
43191 struct s6x0_state {
43192 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43193-};
43194+} __no_const;
43195
43196 /* debug */
43197 static int dvb_usb_dw2102_debug;
43198diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43199index f129551..ecf6514 100644
43200--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43201+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43202@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43203 __u32 reserved;
43204 };
43205
43206-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43207+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43208 enum v4l2_memory memory)
43209 {
43210 void __user *up_pln;
43211@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43212 return 0;
43213 }
43214
43215-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43216+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43217 enum v4l2_memory memory)
43218 {
43219 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43220@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43221 put_user(kp->start_block, &up->start_block) ||
43222 put_user(kp->blocks, &up->blocks) ||
43223 put_user(tmp, &up->edid) ||
43224- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43225+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43226 return -EFAULT;
43227 return 0;
43228 }
43229diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43230index 8ed5da2..47fee46 100644
43231--- a/drivers/media/v4l2-core/v4l2-device.c
43232+++ b/drivers/media/v4l2-core/v4l2-device.c
43233@@ -74,9 +74,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43234 EXPORT_SYMBOL_GPL(v4l2_device_put);
43235
43236 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43237- atomic_t *instance)
43238+ atomic_unchecked_t *instance)
43239 {
43240- int num = atomic_inc_return(instance) - 1;
43241+ int num = atomic_inc_return_unchecked(instance) - 1;
43242 int len = strlen(basename);
43243
43244 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43245diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43246index 7658586..1079260 100644
43247--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43248+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43249@@ -1995,7 +1995,8 @@ struct v4l2_ioctl_info {
43250 struct file *file, void *fh, void *p);
43251 } u;
43252 void (*debug)(const void *arg, bool write_only);
43253-};
43254+} __do_const;
43255+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43256
43257 /* This control needs a priority check */
43258 #define INFO_FL_PRIO (1 << 0)
43259@@ -2177,7 +2178,7 @@ static long __video_do_ioctl(struct file *file,
43260 struct video_device *vfd = video_devdata(file);
43261 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43262 bool write_only = false;
43263- struct v4l2_ioctl_info default_info;
43264+ v4l2_ioctl_info_no_const default_info;
43265 const struct v4l2_ioctl_info *info;
43266 void *fh = file->private_data;
43267 struct v4l2_fh *vfh = NULL;
43268@@ -2251,7 +2252,7 @@ done:
43269 }
43270
43271 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43272- void * __user *user_ptr, void ***kernel_ptr)
43273+ void __user **user_ptr, void ***kernel_ptr)
43274 {
43275 int ret = 0;
43276
43277@@ -2267,7 +2268,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43278 ret = -EINVAL;
43279 break;
43280 }
43281- *user_ptr = (void __user *)buf->m.planes;
43282+ *user_ptr = (void __force_user *)buf->m.planes;
43283 *kernel_ptr = (void *)&buf->m.planes;
43284 *array_size = sizeof(struct v4l2_plane) * buf->length;
43285 ret = 1;
43286@@ -2302,7 +2303,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43287 ret = -EINVAL;
43288 break;
43289 }
43290- *user_ptr = (void __user *)ctrls->controls;
43291+ *user_ptr = (void __force_user *)ctrls->controls;
43292 *kernel_ptr = (void *)&ctrls->controls;
43293 *array_size = sizeof(struct v4l2_ext_control)
43294 * ctrls->count;
43295diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43296index 767ff4d..c69d259 100644
43297--- a/drivers/message/fusion/mptbase.c
43298+++ b/drivers/message/fusion/mptbase.c
43299@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43300 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43301 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43302
43303+#ifdef CONFIG_GRKERNSEC_HIDESYM
43304+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43305+#else
43306 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43307 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43308+#endif
43309+
43310 /*
43311 * Rounding UP to nearest 4-kB boundary here...
43312 */
43313@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43314 ioc->facts.GlobalCredits);
43315
43316 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43317+#ifdef CONFIG_GRKERNSEC_HIDESYM
43318+ NULL, NULL);
43319+#else
43320 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43321+#endif
43322 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43323 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43324 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43325diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43326index dd239bd..689c4f7 100644
43327--- a/drivers/message/fusion/mptsas.c
43328+++ b/drivers/message/fusion/mptsas.c
43329@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43330 return 0;
43331 }
43332
43333+static inline void
43334+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43335+{
43336+ if (phy_info->port_details) {
43337+ phy_info->port_details->rphy = rphy;
43338+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43339+ ioc->name, rphy));
43340+ }
43341+
43342+ if (rphy) {
43343+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43344+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43345+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43346+ ioc->name, rphy, rphy->dev.release));
43347+ }
43348+}
43349+
43350 /* no mutex */
43351 static void
43352 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43353@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43354 return NULL;
43355 }
43356
43357-static inline void
43358-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43359-{
43360- if (phy_info->port_details) {
43361- phy_info->port_details->rphy = rphy;
43362- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43363- ioc->name, rphy));
43364- }
43365-
43366- if (rphy) {
43367- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43368- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43369- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43370- ioc->name, rphy, rphy->dev.release));
43371- }
43372-}
43373-
43374 static inline struct sas_port *
43375 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43376 {
43377diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43378index 727819c..ad74694 100644
43379--- a/drivers/message/fusion/mptscsih.c
43380+++ b/drivers/message/fusion/mptscsih.c
43381@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43382
43383 h = shost_priv(SChost);
43384
43385- if (h) {
43386- if (h->info_kbuf == NULL)
43387- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43388- return h->info_kbuf;
43389- h->info_kbuf[0] = '\0';
43390+ if (!h)
43391+ return NULL;
43392
43393- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43394- h->info_kbuf[size-1] = '\0';
43395- }
43396+ if (h->info_kbuf == NULL)
43397+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43398+ return h->info_kbuf;
43399+ h->info_kbuf[0] = '\0';
43400+
43401+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43402+ h->info_kbuf[size-1] = '\0';
43403
43404 return h->info_kbuf;
43405 }
43406diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43407index b7d87cd..9890039 100644
43408--- a/drivers/message/i2o/i2o_proc.c
43409+++ b/drivers/message/i2o/i2o_proc.c
43410@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43411 "Array Controller Device"
43412 };
43413
43414-static char *chtostr(char *tmp, u8 *chars, int n)
43415-{
43416- tmp[0] = 0;
43417- return strncat(tmp, (char *)chars, n);
43418-}
43419-
43420 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43421 char *group)
43422 {
43423@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43424 } *result;
43425
43426 i2o_exec_execute_ddm_table ddm_table;
43427- char tmp[28 + 1];
43428
43429 result = kmalloc(sizeof(*result), GFP_KERNEL);
43430 if (!result)
43431@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43432
43433 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43434 seq_printf(seq, "%-#8x", ddm_table.module_id);
43435- seq_printf(seq, "%-29s",
43436- chtostr(tmp, ddm_table.module_name_version, 28));
43437+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43438 seq_printf(seq, "%9d ", ddm_table.data_size);
43439 seq_printf(seq, "%8d", ddm_table.code_size);
43440
43441@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43442
43443 i2o_driver_result_table *result;
43444 i2o_driver_store_table *dst;
43445- char tmp[28 + 1];
43446
43447 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43448 if (result == NULL)
43449@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43450
43451 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43452 seq_printf(seq, "%-#8x", dst->module_id);
43453- seq_printf(seq, "%-29s",
43454- chtostr(tmp, dst->module_name_version, 28));
43455- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43456+ seq_printf(seq, "%-.28s", dst->module_name_version);
43457+ seq_printf(seq, "%-.8s", dst->date);
43458 seq_printf(seq, "%8d ", dst->module_size);
43459 seq_printf(seq, "%8d ", dst->mpb_size);
43460 seq_printf(seq, "0x%04x", dst->module_flags);
43461@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43462 // == (allow) 512d bytes (max)
43463 static u16 *work16 = (u16 *) work32;
43464 int token;
43465- char tmp[16 + 1];
43466
43467 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43468
43469@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43470 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43471 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43472 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43473- seq_printf(seq, "Vendor info : %s\n",
43474- chtostr(tmp, (u8 *) (work32 + 2), 16));
43475- seq_printf(seq, "Product info : %s\n",
43476- chtostr(tmp, (u8 *) (work32 + 6), 16));
43477- seq_printf(seq, "Description : %s\n",
43478- chtostr(tmp, (u8 *) (work32 + 10), 16));
43479- seq_printf(seq, "Product rev. : %s\n",
43480- chtostr(tmp, (u8 *) (work32 + 14), 8));
43481+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43482+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43483+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43484+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43485
43486 seq_printf(seq, "Serial number : ");
43487 print_serial_number(seq, (u8 *) (work32 + 16),
43488@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43489 u8 pad[256]; // allow up to 256 byte (max) serial number
43490 } result;
43491
43492- char tmp[24 + 1];
43493-
43494 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43495
43496 if (token < 0) {
43497@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43498 }
43499
43500 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43501- seq_printf(seq, "Module name : %s\n",
43502- chtostr(tmp, result.module_name, 24));
43503- seq_printf(seq, "Module revision : %s\n",
43504- chtostr(tmp, result.module_rev, 8));
43505+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43506+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43507
43508 seq_printf(seq, "Serial number : ");
43509 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43510@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43511 u8 instance_number[4];
43512 } result;
43513
43514- char tmp[64 + 1];
43515-
43516 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43517
43518 if (token < 0) {
43519@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43520 return 0;
43521 }
43522
43523- seq_printf(seq, "Device name : %s\n",
43524- chtostr(tmp, result.device_name, 64));
43525- seq_printf(seq, "Service name : %s\n",
43526- chtostr(tmp, result.service_name, 64));
43527- seq_printf(seq, "Physical name : %s\n",
43528- chtostr(tmp, result.physical_location, 64));
43529- seq_printf(seq, "Instance number : %s\n",
43530- chtostr(tmp, result.instance_number, 4));
43531+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43532+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43533+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43534+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43535
43536 return 0;
43537 }
43538diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43539index a8c08f3..155fe3d 100644
43540--- a/drivers/message/i2o/iop.c
43541+++ b/drivers/message/i2o/iop.c
43542@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43543
43544 spin_lock_irqsave(&c->context_list_lock, flags);
43545
43546- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43547- atomic_inc(&c->context_list_counter);
43548+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43549+ atomic_inc_unchecked(&c->context_list_counter);
43550
43551- entry->context = atomic_read(&c->context_list_counter);
43552+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43553
43554 list_add(&entry->list, &c->context_list);
43555
43556@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43557
43558 #if BITS_PER_LONG == 64
43559 spin_lock_init(&c->context_list_lock);
43560- atomic_set(&c->context_list_counter, 0);
43561+ atomic_set_unchecked(&c->context_list_counter, 0);
43562 INIT_LIST_HEAD(&c->context_list);
43563 #endif
43564
43565diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43566index 45ece11..8efa218 100644
43567--- a/drivers/mfd/janz-cmodio.c
43568+++ b/drivers/mfd/janz-cmodio.c
43569@@ -13,6 +13,7 @@
43570
43571 #include <linux/kernel.h>
43572 #include <linux/module.h>
43573+#include <linux/slab.h>
43574 #include <linux/init.h>
43575 #include <linux/pci.h>
43576 #include <linux/interrupt.h>
43577diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43578index a5f9888..1c0ed56 100644
43579--- a/drivers/mfd/twl4030-irq.c
43580+++ b/drivers/mfd/twl4030-irq.c
43581@@ -35,6 +35,7 @@
43582 #include <linux/of.h>
43583 #include <linux/irqdomain.h>
43584 #include <linux/i2c/twl.h>
43585+#include <asm/pgtable.h>
43586
43587 #include "twl-core.h"
43588
43589@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43590 * Install an irq handler for each of the SIH modules;
43591 * clone dummy irq_chip since PIH can't *do* anything
43592 */
43593- twl4030_irq_chip = dummy_irq_chip;
43594- twl4030_irq_chip.name = "twl4030";
43595+ pax_open_kernel();
43596+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43597+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43598
43599- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43600+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43601+ pax_close_kernel();
43602
43603 for (i = irq_base; i < irq_end; i++) {
43604 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43605diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43606index 277a8db..0e0b754 100644
43607--- a/drivers/mfd/twl6030-irq.c
43608+++ b/drivers/mfd/twl6030-irq.c
43609@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43610 * install an irq handler for each of the modules;
43611 * clone dummy irq_chip since PIH can't *do* anything
43612 */
43613- twl6030_irq_chip = dummy_irq_chip;
43614- twl6030_irq_chip.name = "twl6030";
43615- twl6030_irq_chip.irq_set_type = NULL;
43616- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43617+ pax_open_kernel();
43618+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43619+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43620+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43621+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43622+ pax_close_kernel();
43623
43624 for (i = irq_base; i < irq_end; i++) {
43625 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43626diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43627index f32550a..e3e52a2 100644
43628--- a/drivers/misc/c2port/core.c
43629+++ b/drivers/misc/c2port/core.c
43630@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43631 mutex_init(&c2dev->mutex);
43632
43633 /* Create binary file */
43634- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43635+ pax_open_kernel();
43636+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43637+ pax_close_kernel();
43638 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43639 if (unlikely(ret))
43640 goto error_device_create_bin_file;
43641diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43642index 36f5d52..32311c3 100644
43643--- a/drivers/misc/kgdbts.c
43644+++ b/drivers/misc/kgdbts.c
43645@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43646 char before[BREAK_INSTR_SIZE];
43647 char after[BREAK_INSTR_SIZE];
43648
43649- probe_kernel_read(before, (char *)kgdbts_break_test,
43650+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43651 BREAK_INSTR_SIZE);
43652 init_simple_test();
43653 ts.tst = plant_and_detach_test;
43654@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43655 /* Activate test with initial breakpoint */
43656 if (!is_early)
43657 kgdb_breakpoint();
43658- probe_kernel_read(after, (char *)kgdbts_break_test,
43659+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43660 BREAK_INSTR_SIZE);
43661 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43662 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43663diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43664index 4cd4a3d..b48cbc7 100644
43665--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43666+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43667@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43668 * the lid is closed. This leads to interrupts as soon as a little move
43669 * is done.
43670 */
43671- atomic_inc(&lis3->count);
43672+ atomic_inc_unchecked(&lis3->count);
43673
43674 wake_up_interruptible(&lis3->misc_wait);
43675 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43676@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43677 if (lis3->pm_dev)
43678 pm_runtime_get_sync(lis3->pm_dev);
43679
43680- atomic_set(&lis3->count, 0);
43681+ atomic_set_unchecked(&lis3->count, 0);
43682 return 0;
43683 }
43684
43685@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43686 add_wait_queue(&lis3->misc_wait, &wait);
43687 while (true) {
43688 set_current_state(TASK_INTERRUPTIBLE);
43689- data = atomic_xchg(&lis3->count, 0);
43690+ data = atomic_xchg_unchecked(&lis3->count, 0);
43691 if (data)
43692 break;
43693
43694@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43695 struct lis3lv02d, miscdev);
43696
43697 poll_wait(file, &lis3->misc_wait, wait);
43698- if (atomic_read(&lis3->count))
43699+ if (atomic_read_unchecked(&lis3->count))
43700 return POLLIN | POLLRDNORM;
43701 return 0;
43702 }
43703diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43704index c439c82..1f20f57 100644
43705--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43706+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43707@@ -297,7 +297,7 @@ struct lis3lv02d {
43708 struct input_polled_dev *idev; /* input device */
43709 struct platform_device *pdev; /* platform device */
43710 struct regulator_bulk_data regulators[2];
43711- atomic_t count; /* interrupt count after last read */
43712+ atomic_unchecked_t count; /* interrupt count after last read */
43713 union axis_conversion ac; /* hw -> logical axis */
43714 int mapped_btns[3];
43715
43716diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43717index 2f30bad..c4c13d0 100644
43718--- a/drivers/misc/sgi-gru/gruhandles.c
43719+++ b/drivers/misc/sgi-gru/gruhandles.c
43720@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43721 unsigned long nsec;
43722
43723 nsec = CLKS2NSEC(clks);
43724- atomic_long_inc(&mcs_op_statistics[op].count);
43725- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43726+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43727+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43728 if (mcs_op_statistics[op].max < nsec)
43729 mcs_op_statistics[op].max = nsec;
43730 }
43731diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43732index 797d796..ae8f01e 100644
43733--- a/drivers/misc/sgi-gru/gruprocfs.c
43734+++ b/drivers/misc/sgi-gru/gruprocfs.c
43735@@ -32,9 +32,9 @@
43736
43737 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43738
43739-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43740+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43741 {
43742- unsigned long val = atomic_long_read(v);
43743+ unsigned long val = atomic_long_read_unchecked(v);
43744
43745 seq_printf(s, "%16lu %s\n", val, id);
43746 }
43747@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43748
43749 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43750 for (op = 0; op < mcsop_last; op++) {
43751- count = atomic_long_read(&mcs_op_statistics[op].count);
43752- total = atomic_long_read(&mcs_op_statistics[op].total);
43753+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43754+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43755 max = mcs_op_statistics[op].max;
43756 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43757 count ? total / count : 0, max);
43758diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43759index 5c3ce24..4915ccb 100644
43760--- a/drivers/misc/sgi-gru/grutables.h
43761+++ b/drivers/misc/sgi-gru/grutables.h
43762@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43763 * GRU statistics.
43764 */
43765 struct gru_stats_s {
43766- atomic_long_t vdata_alloc;
43767- atomic_long_t vdata_free;
43768- atomic_long_t gts_alloc;
43769- atomic_long_t gts_free;
43770- atomic_long_t gms_alloc;
43771- atomic_long_t gms_free;
43772- atomic_long_t gts_double_allocate;
43773- atomic_long_t assign_context;
43774- atomic_long_t assign_context_failed;
43775- atomic_long_t free_context;
43776- atomic_long_t load_user_context;
43777- atomic_long_t load_kernel_context;
43778- atomic_long_t lock_kernel_context;
43779- atomic_long_t unlock_kernel_context;
43780- atomic_long_t steal_user_context;
43781- atomic_long_t steal_kernel_context;
43782- atomic_long_t steal_context_failed;
43783- atomic_long_t nopfn;
43784- atomic_long_t asid_new;
43785- atomic_long_t asid_next;
43786- atomic_long_t asid_wrap;
43787- atomic_long_t asid_reuse;
43788- atomic_long_t intr;
43789- atomic_long_t intr_cbr;
43790- atomic_long_t intr_tfh;
43791- atomic_long_t intr_spurious;
43792- atomic_long_t intr_mm_lock_failed;
43793- atomic_long_t call_os;
43794- atomic_long_t call_os_wait_queue;
43795- atomic_long_t user_flush_tlb;
43796- atomic_long_t user_unload_context;
43797- atomic_long_t user_exception;
43798- atomic_long_t set_context_option;
43799- atomic_long_t check_context_retarget_intr;
43800- atomic_long_t check_context_unload;
43801- atomic_long_t tlb_dropin;
43802- atomic_long_t tlb_preload_page;
43803- atomic_long_t tlb_dropin_fail_no_asid;
43804- atomic_long_t tlb_dropin_fail_upm;
43805- atomic_long_t tlb_dropin_fail_invalid;
43806- atomic_long_t tlb_dropin_fail_range_active;
43807- atomic_long_t tlb_dropin_fail_idle;
43808- atomic_long_t tlb_dropin_fail_fmm;
43809- atomic_long_t tlb_dropin_fail_no_exception;
43810- atomic_long_t tfh_stale_on_fault;
43811- atomic_long_t mmu_invalidate_range;
43812- atomic_long_t mmu_invalidate_page;
43813- atomic_long_t flush_tlb;
43814- atomic_long_t flush_tlb_gru;
43815- atomic_long_t flush_tlb_gru_tgh;
43816- atomic_long_t flush_tlb_gru_zero_asid;
43817+ atomic_long_unchecked_t vdata_alloc;
43818+ atomic_long_unchecked_t vdata_free;
43819+ atomic_long_unchecked_t gts_alloc;
43820+ atomic_long_unchecked_t gts_free;
43821+ atomic_long_unchecked_t gms_alloc;
43822+ atomic_long_unchecked_t gms_free;
43823+ atomic_long_unchecked_t gts_double_allocate;
43824+ atomic_long_unchecked_t assign_context;
43825+ atomic_long_unchecked_t assign_context_failed;
43826+ atomic_long_unchecked_t free_context;
43827+ atomic_long_unchecked_t load_user_context;
43828+ atomic_long_unchecked_t load_kernel_context;
43829+ atomic_long_unchecked_t lock_kernel_context;
43830+ atomic_long_unchecked_t unlock_kernel_context;
43831+ atomic_long_unchecked_t steal_user_context;
43832+ atomic_long_unchecked_t steal_kernel_context;
43833+ atomic_long_unchecked_t steal_context_failed;
43834+ atomic_long_unchecked_t nopfn;
43835+ atomic_long_unchecked_t asid_new;
43836+ atomic_long_unchecked_t asid_next;
43837+ atomic_long_unchecked_t asid_wrap;
43838+ atomic_long_unchecked_t asid_reuse;
43839+ atomic_long_unchecked_t intr;
43840+ atomic_long_unchecked_t intr_cbr;
43841+ atomic_long_unchecked_t intr_tfh;
43842+ atomic_long_unchecked_t intr_spurious;
43843+ atomic_long_unchecked_t intr_mm_lock_failed;
43844+ atomic_long_unchecked_t call_os;
43845+ atomic_long_unchecked_t call_os_wait_queue;
43846+ atomic_long_unchecked_t user_flush_tlb;
43847+ atomic_long_unchecked_t user_unload_context;
43848+ atomic_long_unchecked_t user_exception;
43849+ atomic_long_unchecked_t set_context_option;
43850+ atomic_long_unchecked_t check_context_retarget_intr;
43851+ atomic_long_unchecked_t check_context_unload;
43852+ atomic_long_unchecked_t tlb_dropin;
43853+ atomic_long_unchecked_t tlb_preload_page;
43854+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43855+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43856+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43857+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43858+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43859+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43860+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43861+ atomic_long_unchecked_t tfh_stale_on_fault;
43862+ atomic_long_unchecked_t mmu_invalidate_range;
43863+ atomic_long_unchecked_t mmu_invalidate_page;
43864+ atomic_long_unchecked_t flush_tlb;
43865+ atomic_long_unchecked_t flush_tlb_gru;
43866+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43867+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43868
43869- atomic_long_t copy_gpa;
43870- atomic_long_t read_gpa;
43871+ atomic_long_unchecked_t copy_gpa;
43872+ atomic_long_unchecked_t read_gpa;
43873
43874- atomic_long_t mesq_receive;
43875- atomic_long_t mesq_receive_none;
43876- atomic_long_t mesq_send;
43877- atomic_long_t mesq_send_failed;
43878- atomic_long_t mesq_noop;
43879- atomic_long_t mesq_send_unexpected_error;
43880- atomic_long_t mesq_send_lb_overflow;
43881- atomic_long_t mesq_send_qlimit_reached;
43882- atomic_long_t mesq_send_amo_nacked;
43883- atomic_long_t mesq_send_put_nacked;
43884- atomic_long_t mesq_page_overflow;
43885- atomic_long_t mesq_qf_locked;
43886- atomic_long_t mesq_qf_noop_not_full;
43887- atomic_long_t mesq_qf_switch_head_failed;
43888- atomic_long_t mesq_qf_unexpected_error;
43889- atomic_long_t mesq_noop_unexpected_error;
43890- atomic_long_t mesq_noop_lb_overflow;
43891- atomic_long_t mesq_noop_qlimit_reached;
43892- atomic_long_t mesq_noop_amo_nacked;
43893- atomic_long_t mesq_noop_put_nacked;
43894- atomic_long_t mesq_noop_page_overflow;
43895+ atomic_long_unchecked_t mesq_receive;
43896+ atomic_long_unchecked_t mesq_receive_none;
43897+ atomic_long_unchecked_t mesq_send;
43898+ atomic_long_unchecked_t mesq_send_failed;
43899+ atomic_long_unchecked_t mesq_noop;
43900+ atomic_long_unchecked_t mesq_send_unexpected_error;
43901+ atomic_long_unchecked_t mesq_send_lb_overflow;
43902+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43903+ atomic_long_unchecked_t mesq_send_amo_nacked;
43904+ atomic_long_unchecked_t mesq_send_put_nacked;
43905+ atomic_long_unchecked_t mesq_page_overflow;
43906+ atomic_long_unchecked_t mesq_qf_locked;
43907+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43908+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43909+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43910+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43911+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43912+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43913+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43914+ atomic_long_unchecked_t mesq_noop_put_nacked;
43915+ atomic_long_unchecked_t mesq_noop_page_overflow;
43916
43917 };
43918
43919@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43920 tghop_invalidate, mcsop_last};
43921
43922 struct mcs_op_statistic {
43923- atomic_long_t count;
43924- atomic_long_t total;
43925+ atomic_long_unchecked_t count;
43926+ atomic_long_unchecked_t total;
43927 unsigned long max;
43928 };
43929
43930@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43931
43932 #define STAT(id) do { \
43933 if (gru_options & OPT_STATS) \
43934- atomic_long_inc(&gru_stats.id); \
43935+ atomic_long_inc_unchecked(&gru_stats.id); \
43936 } while (0)
43937
43938 #ifdef CONFIG_SGI_GRU_DEBUG
43939diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43940index c862cd4..0d176fe 100644
43941--- a/drivers/misc/sgi-xp/xp.h
43942+++ b/drivers/misc/sgi-xp/xp.h
43943@@ -288,7 +288,7 @@ struct xpc_interface {
43944 xpc_notify_func, void *);
43945 void (*received) (short, int, void *);
43946 enum xp_retval (*partid_to_nasids) (short, void *);
43947-};
43948+} __no_const;
43949
43950 extern struct xpc_interface xpc_interface;
43951
43952diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43953index b94d5f7..7f494c5 100644
43954--- a/drivers/misc/sgi-xp/xpc.h
43955+++ b/drivers/misc/sgi-xp/xpc.h
43956@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43957 void (*received_payload) (struct xpc_channel *, void *);
43958 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43959 };
43960+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43961
43962 /* struct xpc_partition act_state values (for XPC HB) */
43963
43964@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43965 /* found in xpc_main.c */
43966 extern struct device *xpc_part;
43967 extern struct device *xpc_chan;
43968-extern struct xpc_arch_operations xpc_arch_ops;
43969+extern xpc_arch_operations_no_const xpc_arch_ops;
43970 extern int xpc_disengage_timelimit;
43971 extern int xpc_disengage_timedout;
43972 extern int xpc_activate_IRQ_rcvd;
43973diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43974index d971817..33bdca5 100644
43975--- a/drivers/misc/sgi-xp/xpc_main.c
43976+++ b/drivers/misc/sgi-xp/xpc_main.c
43977@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43978 .notifier_call = xpc_system_die,
43979 };
43980
43981-struct xpc_arch_operations xpc_arch_ops;
43982+xpc_arch_operations_no_const xpc_arch_ops;
43983
43984 /*
43985 * Timer function to enforce the timelimit on the partition disengage.
43986@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43987
43988 if (((die_args->trapnr == X86_TRAP_MF) ||
43989 (die_args->trapnr == X86_TRAP_XF)) &&
43990- !user_mode_vm(die_args->regs))
43991+ !user_mode(die_args->regs))
43992 xpc_die_deactivate();
43993
43994 break;
43995diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43996index 49f04bc..65660c2 100644
43997--- a/drivers/mmc/core/mmc_ops.c
43998+++ b/drivers/mmc/core/mmc_ops.c
43999@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44000 void *data_buf;
44001 int is_on_stack;
44002
44003- is_on_stack = object_is_on_stack(buf);
44004+ is_on_stack = object_starts_on_stack(buf);
44005 if (is_on_stack) {
44006 /*
44007 * dma onto stack is unsafe/nonportable, but callers to this
44008diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44009index 0b74189..818358f 100644
44010--- a/drivers/mmc/host/dw_mmc.h
44011+++ b/drivers/mmc/host/dw_mmc.h
44012@@ -202,5 +202,5 @@ struct dw_mci_drv_data {
44013 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44014 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44015 int (*parse_dt)(struct dw_mci *host);
44016-};
44017+} __do_const;
44018 #endif /* _DW_MMC_H_ */
44019diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44020index c6f6246..60760a8 100644
44021--- a/drivers/mmc/host/sdhci-s3c.c
44022+++ b/drivers/mmc/host/sdhci-s3c.c
44023@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44024 * we can use overriding functions instead of default.
44025 */
44026 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44027- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44028- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44029- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44030+ pax_open_kernel();
44031+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44032+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44033+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44034+ pax_close_kernel();
44035 }
44036
44037 /* It supports additional host capabilities if needed */
44038diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44039index 0c8bb6b..6f35deb 100644
44040--- a/drivers/mtd/nand/denali.c
44041+++ b/drivers/mtd/nand/denali.c
44042@@ -24,6 +24,7 @@
44043 #include <linux/slab.h>
44044 #include <linux/mtd/mtd.h>
44045 #include <linux/module.h>
44046+#include <linux/slab.h>
44047
44048 #include "denali.h"
44049
44050diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44051index 51b9d6a..52af9a7 100644
44052--- a/drivers/mtd/nftlmount.c
44053+++ b/drivers/mtd/nftlmount.c
44054@@ -24,6 +24,7 @@
44055 #include <asm/errno.h>
44056 #include <linux/delay.h>
44057 #include <linux/slab.h>
44058+#include <linux/sched.h>
44059 #include <linux/mtd/mtd.h>
44060 #include <linux/mtd/nand.h>
44061 #include <linux/mtd/nftl.h>
44062diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44063index f9d5615..99dd95f 100644
44064--- a/drivers/mtd/sm_ftl.c
44065+++ b/drivers/mtd/sm_ftl.c
44066@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44067 #define SM_CIS_VENDOR_OFFSET 0x59
44068 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44069 {
44070- struct attribute_group *attr_group;
44071+ attribute_group_no_const *attr_group;
44072 struct attribute **attributes;
44073 struct sm_sysfs_attribute *vendor_attribute;
44074
44075diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44076index f975696..4597e21 100644
44077--- a/drivers/net/bonding/bond_main.c
44078+++ b/drivers/net/bonding/bond_main.c
44079@@ -4870,7 +4870,7 @@ static unsigned int bond_get_num_tx_queues(void)
44080 return tx_queues;
44081 }
44082
44083-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44084+static struct rtnl_link_ops bond_link_ops = {
44085 .kind = "bond",
44086 .priv_size = sizeof(struct bonding),
44087 .setup = bond_setup,
44088@@ -4995,8 +4995,8 @@ static void __exit bonding_exit(void)
44089
44090 bond_destroy_debugfs();
44091
44092- rtnl_link_unregister(&bond_link_ops);
44093 unregister_pernet_subsys(&bond_net_ops);
44094+ rtnl_link_unregister(&bond_link_ops);
44095
44096 #ifdef CONFIG_NET_POLL_CONTROLLER
44097 /*
44098diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44099index e1d2643..7f4133b 100644
44100--- a/drivers/net/ethernet/8390/ax88796.c
44101+++ b/drivers/net/ethernet/8390/ax88796.c
44102@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44103 if (ax->plat->reg_offsets)
44104 ei_local->reg_offset = ax->plat->reg_offsets;
44105 else {
44106+ resource_size_t _mem_size = mem_size;
44107+ do_div(_mem_size, 0x18);
44108 ei_local->reg_offset = ax->reg_offsets;
44109 for (ret = 0; ret < 0x18; ret++)
44110- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44111+ ax->reg_offsets[ret] = _mem_size * ret;
44112 }
44113
44114 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44115diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44116index 151675d..0139a9d 100644
44117--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44118+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44119@@ -1112,7 +1112,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44120 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44121 {
44122 /* RX_MODE controlling object */
44123- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44124+ bnx2x_init_rx_mode_obj(bp);
44125
44126 /* multicast configuration controlling object */
44127 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44128diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
44129index ce1a916..10b52b0 100644
44130--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
44131+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
44132@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
44133 struct bnx2x *bp = netdev_priv(dev);
44134
44135 /* Use the ethtool_dump "flag" field as the dump preset index */
44136+ if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
44137+ return -EINVAL;
44138+
44139 bp->dump_preset_idx = val->flag;
44140 return 0;
44141 }
44142@@ -986,8 +989,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
44143 struct bnx2x *bp = netdev_priv(dev);
44144 struct dump_header dump_hdr = {0};
44145
44146- memset(p, 0, dump->len);
44147-
44148 /* Disable parity attentions as long as following dump may
44149 * cause false alarms by reading never written registers. We
44150 * will re-enable parity attentions right after the dump.
44151diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
44152index b4c9dea..2a9927f 100644
44153--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
44154+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
44155@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
44156 bp->min_msix_vec_cnt = 2;
44157 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
44158
44159+ bp->dump_preset_idx = 1;
44160+
44161 return rc;
44162 }
44163
44164diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44165index 32a9609..0b1c53a 100644
44166--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44167+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44168@@ -2387,15 +2387,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44169 return rc;
44170 }
44171
44172-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44173- struct bnx2x_rx_mode_obj *o)
44174+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44175 {
44176 if (CHIP_IS_E1x(bp)) {
44177- o->wait_comp = bnx2x_empty_rx_mode_wait;
44178- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44179+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44180+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44181 } else {
44182- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44183- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44184+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44185+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44186 }
44187 }
44188
44189diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44190index 43c00bc..dd1d03d 100644
44191--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44192+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44193@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44194
44195 /********************* RX MODE ****************/
44196
44197-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44198- struct bnx2x_rx_mode_obj *o);
44199+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44200
44201 /**
44202 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44203diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44204index ff6e30e..87e8452 100644
44205--- a/drivers/net/ethernet/broadcom/tg3.h
44206+++ b/drivers/net/ethernet/broadcom/tg3.h
44207@@ -147,6 +147,7 @@
44208 #define CHIPREV_ID_5750_A0 0x4000
44209 #define CHIPREV_ID_5750_A1 0x4001
44210 #define CHIPREV_ID_5750_A3 0x4003
44211+#define CHIPREV_ID_5750_C1 0x4201
44212 #define CHIPREV_ID_5750_C2 0x4202
44213 #define CHIPREV_ID_5752_A0_HW 0x5000
44214 #define CHIPREV_ID_5752_A0 0x6000
44215diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
44216index 71497e8..b650951 100644
44217--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
44218+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
44219@@ -3037,7 +3037,9 @@ static void t3_io_resume(struct pci_dev *pdev)
44220 CH_ALERT(adapter, "adapter recovering, PEX ERR 0x%x\n",
44221 t3_read_reg(adapter, A_PCIE_PEX_ERR));
44222
44223+ rtnl_lock();
44224 t3_resume_ports(adapter);
44225+ rtnl_unlock();
44226 }
44227
44228 static const struct pci_error_handlers t3_err_handler = {
44229diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44230index 8cffcdf..aadf043 100644
44231--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44232+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44233@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44234 */
44235 struct l2t_skb_cb {
44236 arp_failure_handler_func arp_failure_handler;
44237-};
44238+} __no_const;
44239
44240 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44241
44242diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44243index 4c83003..2a2a5b9 100644
44244--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44245+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44246@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44247 for (i=0; i<ETH_ALEN; i++) {
44248 tmp.addr[i] = dev->dev_addr[i];
44249 }
44250- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44251+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44252 break;
44253
44254 case DE4X5_SET_HWADDR: /* Set the hardware address */
44255@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44256 spin_lock_irqsave(&lp->lock, flags);
44257 memcpy(&statbuf, &lp->pktStats, ioc->len);
44258 spin_unlock_irqrestore(&lp->lock, flags);
44259- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44260+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44261 return -EFAULT;
44262 break;
44263 }
44264diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44265index 6e43426..1bd8365 100644
44266--- a/drivers/net/ethernet/emulex/benet/be_main.c
44267+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44268@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44269
44270 if (wrapped)
44271 newacc += 65536;
44272- ACCESS_ONCE(*acc) = newacc;
44273+ ACCESS_ONCE_RW(*acc) = newacc;
44274 }
44275
44276 void populate_erx_stats(struct be_adapter *adapter,
44277diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44278index 21b85fb..b49e5fc 100644
44279--- a/drivers/net/ethernet/faraday/ftgmac100.c
44280+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44281@@ -31,6 +31,8 @@
44282 #include <linux/netdevice.h>
44283 #include <linux/phy.h>
44284 #include <linux/platform_device.h>
44285+#include <linux/interrupt.h>
44286+#include <linux/irqreturn.h>
44287 #include <net/ip.h>
44288
44289 #include "ftgmac100.h"
44290diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44291index a6eda8d..935d273 100644
44292--- a/drivers/net/ethernet/faraday/ftmac100.c
44293+++ b/drivers/net/ethernet/faraday/ftmac100.c
44294@@ -31,6 +31,8 @@
44295 #include <linux/module.h>
44296 #include <linux/netdevice.h>
44297 #include <linux/platform_device.h>
44298+#include <linux/interrupt.h>
44299+#include <linux/irqreturn.h>
44300
44301 #include "ftmac100.h"
44302
44303diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44304index 331987d..3be1135 100644
44305--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44306+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44307@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44308 }
44309
44310 /* update the base incval used to calculate frequency adjustment */
44311- ACCESS_ONCE(adapter->base_incval) = incval;
44312+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44313 smp_mb();
44314
44315 /* need lock to prevent incorrect read while modifying cyclecounter */
44316diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44317index fbe5363..266b4e3 100644
44318--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44319+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44320@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44321 struct __vxge_hw_fifo *fifo;
44322 struct vxge_hw_fifo_config *config;
44323 u32 txdl_size, txdl_per_memblock;
44324- struct vxge_hw_mempool_cbs fifo_mp_callback;
44325+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44326+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44327+ };
44328+
44329 struct __vxge_hw_virtualpath *vpath;
44330
44331 if ((vp == NULL) || (attr == NULL)) {
44332@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44333 goto exit;
44334 }
44335
44336- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44337-
44338 fifo->mempool =
44339 __vxge_hw_mempool_create(vpath->hldev,
44340 fifo->config->memblock_size,
44341diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44342index 5e7fb1d..f8d1810 100644
44343--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44344+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44345@@ -1948,7 +1948,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44346 op_mode = QLC_83XX_DEFAULT_OPMODE;
44347
44348 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44349- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44350+ pax_open_kernel();
44351+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44352+ pax_close_kernel();
44353 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44354 } else {
44355 return -EIO;
44356diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44357index b0c3de9..fc5857e 100644
44358--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44359+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44360@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44361 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
44362 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44363 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44364- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44365+ pax_open_kernel();
44366+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44367+ pax_close_kernel();
44368 } else if (priv_level == QLCNIC_PRIV_FUNC) {
44369 ahw->op_mode = QLCNIC_PRIV_FUNC;
44370 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44371- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44372+ pax_open_kernel();
44373+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44374+ pax_close_kernel();
44375 } else if (priv_level == QLCNIC_MGMT_FUNC) {
44376 ahw->op_mode = QLCNIC_MGMT_FUNC;
44377 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44378- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44379+ pax_open_kernel();
44380+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44381+ pax_close_kernel();
44382 } else {
44383 return -EIO;
44384 }
44385diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
44386index 6acf82b..14b097e 100644
44387--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
44388+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
44389@@ -206,10 +206,10 @@ int qlcnic_fw_cmd_set_drv_version(struct qlcnic_adapter *adapter)
44390 if (err) {
44391 dev_info(&adapter->pdev->dev,
44392 "Failed to set driver version in firmware\n");
44393- return -EIO;
44394+ err = -EIO;
44395 }
44396-
44397- return 0;
44398+ qlcnic_free_mbx_args(&cmd);
44399+ return err;
44400 }
44401
44402 int
44403diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
44404index d3f8797..82a03d3 100644
44405--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
44406+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
44407@@ -262,7 +262,7 @@ void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
44408
44409 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
44410 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
44411- memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
44412+ memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
44413
44414 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
44415 vlan_req->vlan_id = cpu_to_le16(vlan_id);
44416diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
44417index 887aebe..9095ff9 100644
44418--- a/drivers/net/ethernet/realtek/8139cp.c
44419+++ b/drivers/net/ethernet/realtek/8139cp.c
44420@@ -524,6 +524,7 @@ rx_status_loop:
44421 PCI_DMA_FROMDEVICE);
44422 if (dma_mapping_error(&cp->pdev->dev, new_mapping)) {
44423 dev->stats.rx_dropped++;
44424+ kfree_skb(new_skb);
44425 goto rx_next;
44426 }
44427
44428diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44429index 393f961..d343034 100644
44430--- a/drivers/net/ethernet/realtek/r8169.c
44431+++ b/drivers/net/ethernet/realtek/r8169.c
44432@@ -753,22 +753,22 @@ struct rtl8169_private {
44433 struct mdio_ops {
44434 void (*write)(struct rtl8169_private *, int, int);
44435 int (*read)(struct rtl8169_private *, int);
44436- } mdio_ops;
44437+ } __no_const mdio_ops;
44438
44439 struct pll_power_ops {
44440 void (*down)(struct rtl8169_private *);
44441 void (*up)(struct rtl8169_private *);
44442- } pll_power_ops;
44443+ } __no_const pll_power_ops;
44444
44445 struct jumbo_ops {
44446 void (*enable)(struct rtl8169_private *);
44447 void (*disable)(struct rtl8169_private *);
44448- } jumbo_ops;
44449+ } __no_const jumbo_ops;
44450
44451 struct csi_ops {
44452 void (*write)(struct rtl8169_private *, int, int);
44453 u32 (*read)(struct rtl8169_private *, int);
44454- } csi_ops;
44455+ } __no_const csi_ops;
44456
44457 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44458 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44459diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44460index 9a95abf..36df7f9 100644
44461--- a/drivers/net/ethernet/sfc/ptp.c
44462+++ b/drivers/net/ethernet/sfc/ptp.c
44463@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44464 (u32)((u64)ptp->start.dma_addr >> 32));
44465
44466 /* Clear flag that signals MC ready */
44467- ACCESS_ONCE(*start) = 0;
44468+ ACCESS_ONCE_RW(*start) = 0;
44469 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44470 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44471
44472diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44473index 50617c5..b13724c 100644
44474--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44475+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44476@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44477
44478 writel(value, ioaddr + MMC_CNTRL);
44479
44480- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44481- MMC_CNTRL, value);
44482+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44483+// MMC_CNTRL, value);
44484 }
44485
44486 /* To mask all all interrupts.*/
44487diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44488index e6fe0d8..2b7d752 100644
44489--- a/drivers/net/hyperv/hyperv_net.h
44490+++ b/drivers/net/hyperv/hyperv_net.h
44491@@ -101,7 +101,7 @@ struct rndis_device {
44492
44493 enum rndis_device_state state;
44494 bool link_state;
44495- atomic_t new_req_id;
44496+ atomic_unchecked_t new_req_id;
44497
44498 spinlock_t request_lock;
44499 struct list_head req_list;
44500diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44501index 0775f0a..d4fb316 100644
44502--- a/drivers/net/hyperv/rndis_filter.c
44503+++ b/drivers/net/hyperv/rndis_filter.c
44504@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44505 * template
44506 */
44507 set = &rndis_msg->msg.set_req;
44508- set->req_id = atomic_inc_return(&dev->new_req_id);
44509+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44510
44511 /* Add to the request list */
44512 spin_lock_irqsave(&dev->request_lock, flags);
44513@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44514
44515 /* Setup the rndis set */
44516 halt = &request->request_msg.msg.halt_req;
44517- halt->req_id = atomic_inc_return(&dev->new_req_id);
44518+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44519
44520 /* Ignore return since this msg is optional. */
44521 rndis_filter_send_request(dev, request);
44522diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44523index bf0d55e..82bcfbd1 100644
44524--- a/drivers/net/ieee802154/fakehard.c
44525+++ b/drivers/net/ieee802154/fakehard.c
44526@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44527 phy->transmit_power = 0xbf;
44528
44529 dev->netdev_ops = &fake_ops;
44530- dev->ml_priv = &fake_mlme;
44531+ dev->ml_priv = (void *)&fake_mlme;
44532
44533 priv = netdev_priv(dev);
44534 priv->phy = phy;
44535diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44536index 6e91931..2b0ebe7 100644
44537--- a/drivers/net/macvlan.c
44538+++ b/drivers/net/macvlan.c
44539@@ -905,13 +905,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44540 int macvlan_link_register(struct rtnl_link_ops *ops)
44541 {
44542 /* common fields */
44543- ops->priv_size = sizeof(struct macvlan_dev);
44544- ops->validate = macvlan_validate;
44545- ops->maxtype = IFLA_MACVLAN_MAX;
44546- ops->policy = macvlan_policy;
44547- ops->changelink = macvlan_changelink;
44548- ops->get_size = macvlan_get_size;
44549- ops->fill_info = macvlan_fill_info;
44550+ pax_open_kernel();
44551+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44552+ *(void **)&ops->validate = macvlan_validate;
44553+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44554+ *(const void **)&ops->policy = macvlan_policy;
44555+ *(void **)&ops->changelink = macvlan_changelink;
44556+ *(void **)&ops->get_size = macvlan_get_size;
44557+ *(void **)&ops->fill_info = macvlan_fill_info;
44558+ pax_close_kernel();
44559
44560 return rtnl_link_register(ops);
44561 };
44562@@ -967,7 +969,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44563 return NOTIFY_DONE;
44564 }
44565
44566-static struct notifier_block macvlan_notifier_block __read_mostly = {
44567+static struct notifier_block macvlan_notifier_block = {
44568 .notifier_call = macvlan_device_event,
44569 };
44570
44571diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44572index 523d6b2..5e16aa1 100644
44573--- a/drivers/net/macvtap.c
44574+++ b/drivers/net/macvtap.c
44575@@ -1110,7 +1110,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44576 return NOTIFY_DONE;
44577 }
44578
44579-static struct notifier_block macvtap_notifier_block __read_mostly = {
44580+static struct notifier_block macvtap_notifier_block = {
44581 .notifier_call = macvtap_device_event,
44582 };
44583
44584diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44585index daec9b0..6428fcb 100644
44586--- a/drivers/net/phy/mdio-bitbang.c
44587+++ b/drivers/net/phy/mdio-bitbang.c
44588@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44589 struct mdiobb_ctrl *ctrl = bus->priv;
44590
44591 module_put(ctrl->ops->owner);
44592+ mdiobus_unregister(bus);
44593 mdiobus_free(bus);
44594 }
44595 EXPORT_SYMBOL(free_mdio_bitbang);
44596diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44597index 72ff14b..11d442d 100644
44598--- a/drivers/net/ppp/ppp_generic.c
44599+++ b/drivers/net/ppp/ppp_generic.c
44600@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44601 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44602 struct ppp_stats stats;
44603 struct ppp_comp_stats cstats;
44604- char *vers;
44605
44606 switch (cmd) {
44607 case SIOCGPPPSTATS:
44608@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44609 break;
44610
44611 case SIOCGPPPVER:
44612- vers = PPP_VERSION;
44613- if (copy_to_user(addr, vers, strlen(vers) + 1))
44614+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44615 break;
44616 err = 0;
44617 break;
44618diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44619index 1252d9c..80e660b 100644
44620--- a/drivers/net/slip/slhc.c
44621+++ b/drivers/net/slip/slhc.c
44622@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44623 register struct tcphdr *thp;
44624 register struct iphdr *ip;
44625 register struct cstate *cs;
44626- int len, hdrlen;
44627+ long len, hdrlen;
44628 unsigned char *cp = icp;
44629
44630 /* We've got a compressed packet; read the change byte */
44631diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44632index b305105..8ead6df 100644
44633--- a/drivers/net/team/team.c
44634+++ b/drivers/net/team/team.c
44635@@ -2682,7 +2682,7 @@ static int team_device_event(struct notifier_block *unused,
44636 return NOTIFY_DONE;
44637 }
44638
44639-static struct notifier_block team_notifier_block __read_mostly = {
44640+static struct notifier_block team_notifier_block = {
44641 .notifier_call = team_device_event,
44642 };
44643
44644diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44645index 2491eb2..1a453eb 100644
44646--- a/drivers/net/tun.c
44647+++ b/drivers/net/tun.c
44648@@ -1076,8 +1076,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
44649 u32 rxhash;
44650
44651 if (!(tun->flags & TUN_NO_PI)) {
44652- if ((len -= sizeof(pi)) > total_len)
44653+ if (len < sizeof(pi))
44654 return -EINVAL;
44655+ len -= sizeof(pi);
44656
44657 if (memcpy_fromiovecend((void *)&pi, iv, 0, sizeof(pi)))
44658 return -EFAULT;
44659@@ -1085,8 +1086,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
44660 }
44661
44662 if (tun->flags & TUN_VNET_HDR) {
44663- if ((len -= tun->vnet_hdr_sz) > total_len)
44664+ if (len < tun->vnet_hdr_sz)
44665 return -EINVAL;
44666+ len -= tun->vnet_hdr_sz;
44667
44668 if (memcpy_fromiovecend((void *)&gso, iv, offset, sizeof(gso)))
44669 return -EFAULT;
44670@@ -1869,7 +1871,7 @@ unlock:
44671 }
44672
44673 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44674- unsigned long arg, int ifreq_len)
44675+ unsigned long arg, size_t ifreq_len)
44676 {
44677 struct tun_file *tfile = file->private_data;
44678 struct tun_struct *tun;
44679@@ -1881,6 +1883,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44680 int vnet_hdr_sz;
44681 int ret;
44682
44683+ if (ifreq_len > sizeof ifr)
44684+ return -EFAULT;
44685+
44686 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44687 if (copy_from_user(&ifr, argp, ifreq_len))
44688 return -EFAULT;
44689diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44690index cba1d46..f703766 100644
44691--- a/drivers/net/usb/hso.c
44692+++ b/drivers/net/usb/hso.c
44693@@ -71,7 +71,7 @@
44694 #include <asm/byteorder.h>
44695 #include <linux/serial_core.h>
44696 #include <linux/serial.h>
44697-
44698+#include <asm/local.h>
44699
44700 #define MOD_AUTHOR "Option Wireless"
44701 #define MOD_DESCRIPTION "USB High Speed Option driver"
44702@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44703 struct urb *urb;
44704
44705 urb = serial->rx_urb[0];
44706- if (serial->port.count > 0) {
44707+ if (atomic_read(&serial->port.count) > 0) {
44708 count = put_rxbuf_data(urb, serial);
44709 if (count == -1)
44710 return;
44711@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44712 DUMP1(urb->transfer_buffer, urb->actual_length);
44713
44714 /* Anyone listening? */
44715- if (serial->port.count == 0)
44716+ if (atomic_read(&serial->port.count) == 0)
44717 return;
44718
44719 if (status == 0) {
44720@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44721 tty_port_tty_set(&serial->port, tty);
44722
44723 /* check for port already opened, if not set the termios */
44724- serial->port.count++;
44725- if (serial->port.count == 1) {
44726+ if (atomic_inc_return(&serial->port.count) == 1) {
44727 serial->rx_state = RX_IDLE;
44728 /* Force default termio settings */
44729 _hso_serial_set_termios(tty, NULL);
44730@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44731 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44732 if (result) {
44733 hso_stop_serial_device(serial->parent);
44734- serial->port.count--;
44735+ atomic_dec(&serial->port.count);
44736 kref_put(&serial->parent->ref, hso_serial_ref_free);
44737 }
44738 } else {
44739@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44740
44741 /* reset the rts and dtr */
44742 /* do the actual close */
44743- serial->port.count--;
44744+ atomic_dec(&serial->port.count);
44745
44746- if (serial->port.count <= 0) {
44747- serial->port.count = 0;
44748+ if (atomic_read(&serial->port.count) <= 0) {
44749+ atomic_set(&serial->port.count, 0);
44750 tty_port_tty_set(&serial->port, NULL);
44751 if (!usb_gone)
44752 hso_stop_serial_device(serial->parent);
44753@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44754
44755 /* the actual setup */
44756 spin_lock_irqsave(&serial->serial_lock, flags);
44757- if (serial->port.count)
44758+ if (atomic_read(&serial->port.count))
44759 _hso_serial_set_termios(tty, old);
44760 else
44761 tty->termios = *old;
44762@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44763 D1("Pending read interrupt on port %d\n", i);
44764 spin_lock(&serial->serial_lock);
44765 if (serial->rx_state == RX_IDLE &&
44766- serial->port.count > 0) {
44767+ atomic_read(&serial->port.count) > 0) {
44768 /* Setup and send a ctrl req read on
44769 * port i */
44770 if (!serial->rx_urb_filled[0]) {
44771@@ -3057,7 +3056,7 @@ static int hso_resume(struct usb_interface *iface)
44772 /* Start all serial ports */
44773 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44774 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44775- if (dev2ser(serial_table[i])->port.count) {
44776+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44777 result =
44778 hso_start_serial_device(serial_table[i], GFP_NOIO);
44779 hso_kick_transmit(dev2ser(serial_table[i]));
44780diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44781index a79e9d3..78cd4fa 100644
44782--- a/drivers/net/usb/sierra_net.c
44783+++ b/drivers/net/usb/sierra_net.c
44784@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44785 /* atomic counter partially included in MAC address to make sure 2 devices
44786 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44787 */
44788-static atomic_t iface_counter = ATOMIC_INIT(0);
44789+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44790
44791 /*
44792 * SYNC Timer Delay definition used to set the expiry time
44793@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44794 dev->net->netdev_ops = &sierra_net_device_ops;
44795
44796 /* change MAC addr to include, ifacenum, and to be unique */
44797- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44798+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44799 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44800
44801 /* we will have to manufacture ethernet headers, prepare template */
44802diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44803index 57325f3..36b181f 100644
44804--- a/drivers/net/vxlan.c
44805+++ b/drivers/net/vxlan.c
44806@@ -1579,7 +1579,7 @@ nla_put_failure:
44807 return -EMSGSIZE;
44808 }
44809
44810-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44811+static struct rtnl_link_ops vxlan_link_ops = {
44812 .kind = "vxlan",
44813 .maxtype = IFLA_VXLAN_MAX,
44814 .policy = vxlan_policy,
44815diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44816index 34c8a33..3261fdc 100644
44817--- a/drivers/net/wireless/at76c50x-usb.c
44818+++ b/drivers/net/wireless/at76c50x-usb.c
44819@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44820 }
44821
44822 /* Convert timeout from the DFU status to jiffies */
44823-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44824+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44825 {
44826 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44827 | (s->poll_timeout[1] << 8)
44828diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44829index 8d78253..bebbb68 100644
44830--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44831+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44832@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44833 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44834 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44835
44836- ACCESS_ONCE(ads->ds_link) = i->link;
44837- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44838+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44839+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44840
44841 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44842 ctl6 = SM(i->keytype, AR_EncrType);
44843@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44844
44845 if ((i->is_first || i->is_last) &&
44846 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44847- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44848+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44849 | set11nTries(i->rates, 1)
44850 | set11nTries(i->rates, 2)
44851 | set11nTries(i->rates, 3)
44852 | (i->dur_update ? AR_DurUpdateEna : 0)
44853 | SM(0, AR_BurstDur);
44854
44855- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44856+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44857 | set11nRate(i->rates, 1)
44858 | set11nRate(i->rates, 2)
44859 | set11nRate(i->rates, 3);
44860 } else {
44861- ACCESS_ONCE(ads->ds_ctl2) = 0;
44862- ACCESS_ONCE(ads->ds_ctl3) = 0;
44863+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44864+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44865 }
44866
44867 if (!i->is_first) {
44868- ACCESS_ONCE(ads->ds_ctl0) = 0;
44869- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44870- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44871+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44872+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44873+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44874 return;
44875 }
44876
44877@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44878 break;
44879 }
44880
44881- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44882+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44883 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44884 | SM(i->txpower, AR_XmitPower)
44885 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44886@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44887 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44888 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44889
44890- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44891- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44892+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44893+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44894
44895 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44896 return;
44897
44898- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44899+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44900 | set11nPktDurRTSCTS(i->rates, 1);
44901
44902- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44903+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44904 | set11nPktDurRTSCTS(i->rates, 3);
44905
44906- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44907+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44908 | set11nRateFlags(i->rates, 1)
44909 | set11nRateFlags(i->rates, 2)
44910 | set11nRateFlags(i->rates, 3)
44911diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44912index 301bf72..3f5654f 100644
44913--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44914+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44915@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44916 (i->qcu << AR_TxQcuNum_S) | desc_len;
44917
44918 checksum += val;
44919- ACCESS_ONCE(ads->info) = val;
44920+ ACCESS_ONCE_RW(ads->info) = val;
44921
44922 checksum += i->link;
44923- ACCESS_ONCE(ads->link) = i->link;
44924+ ACCESS_ONCE_RW(ads->link) = i->link;
44925
44926 checksum += i->buf_addr[0];
44927- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44928+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44929 checksum += i->buf_addr[1];
44930- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44931+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44932 checksum += i->buf_addr[2];
44933- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44934+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44935 checksum += i->buf_addr[3];
44936- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44937+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44938
44939 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44940- ACCESS_ONCE(ads->ctl3) = val;
44941+ ACCESS_ONCE_RW(ads->ctl3) = val;
44942 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44943- ACCESS_ONCE(ads->ctl5) = val;
44944+ ACCESS_ONCE_RW(ads->ctl5) = val;
44945 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44946- ACCESS_ONCE(ads->ctl7) = val;
44947+ ACCESS_ONCE_RW(ads->ctl7) = val;
44948 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44949- ACCESS_ONCE(ads->ctl9) = val;
44950+ ACCESS_ONCE_RW(ads->ctl9) = val;
44951
44952 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44953- ACCESS_ONCE(ads->ctl10) = checksum;
44954+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44955
44956 if (i->is_first || i->is_last) {
44957- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44958+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44959 | set11nTries(i->rates, 1)
44960 | set11nTries(i->rates, 2)
44961 | set11nTries(i->rates, 3)
44962 | (i->dur_update ? AR_DurUpdateEna : 0)
44963 | SM(0, AR_BurstDur);
44964
44965- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44966+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44967 | set11nRate(i->rates, 1)
44968 | set11nRate(i->rates, 2)
44969 | set11nRate(i->rates, 3);
44970 } else {
44971- ACCESS_ONCE(ads->ctl13) = 0;
44972- ACCESS_ONCE(ads->ctl14) = 0;
44973+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44974+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44975 }
44976
44977 ads->ctl20 = 0;
44978@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44979
44980 ctl17 = SM(i->keytype, AR_EncrType);
44981 if (!i->is_first) {
44982- ACCESS_ONCE(ads->ctl11) = 0;
44983- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44984- ACCESS_ONCE(ads->ctl15) = 0;
44985- ACCESS_ONCE(ads->ctl16) = 0;
44986- ACCESS_ONCE(ads->ctl17) = ctl17;
44987- ACCESS_ONCE(ads->ctl18) = 0;
44988- ACCESS_ONCE(ads->ctl19) = 0;
44989+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44990+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44991+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44992+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44993+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44994+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44995+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44996 return;
44997 }
44998
44999- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45000+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45001 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45002 | SM(i->txpower, AR_XmitPower)
45003 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45004@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45005 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45006 ctl12 |= SM(val, AR_PAPRDChainMask);
45007
45008- ACCESS_ONCE(ads->ctl12) = ctl12;
45009- ACCESS_ONCE(ads->ctl17) = ctl17;
45010+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45011+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45012
45013- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45014+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45015 | set11nPktDurRTSCTS(i->rates, 1);
45016
45017- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45018+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45019 | set11nPktDurRTSCTS(i->rates, 3);
45020
45021- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
45022+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
45023 | set11nRateFlags(i->rates, 1)
45024 | set11nRateFlags(i->rates, 2)
45025 | set11nRateFlags(i->rates, 3)
45026 | SM(i->rtscts_rate, AR_RTSCTSRate);
45027
45028- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45029+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45030 }
45031
45032 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45033diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45034index ae30343..a117806 100644
45035--- a/drivers/net/wireless/ath/ath9k/hw.h
45036+++ b/drivers/net/wireless/ath/ath9k/hw.h
45037@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
45038
45039 /* ANI */
45040 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45041-};
45042+} __no_const;
45043
45044 /**
45045 * struct ath_spec_scan - parameters for Atheros spectral scan
45046@@ -721,7 +721,7 @@ struct ath_hw_ops {
45047 struct ath_spec_scan *param);
45048 void (*spectral_scan_trigger)(struct ath_hw *ah);
45049 void (*spectral_scan_wait)(struct ath_hw *ah);
45050-};
45051+} __no_const;
45052
45053 struct ath_nf_limits {
45054 s16 max;
45055diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45056index b37a582..680835d 100644
45057--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45058+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45059@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45060 */
45061 if (il3945_mod_params.disable_hw_scan) {
45062 D_INFO("Disabling hw_scan\n");
45063- il3945_mac_ops.hw_scan = NULL;
45064+ pax_open_kernel();
45065+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45066+ pax_close_kernel();
45067 }
45068
45069 D_INFO("*** LOAD DRIVER ***\n");
45070diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45071index d532948..e0d8bb1 100644
45072--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45073+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45074@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45075 {
45076 struct iwl_priv *priv = file->private_data;
45077 char buf[64];
45078- int buf_size;
45079+ size_t buf_size;
45080 u32 offset, len;
45081
45082 memset(buf, 0, sizeof(buf));
45083@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45084 struct iwl_priv *priv = file->private_data;
45085
45086 char buf[8];
45087- int buf_size;
45088+ size_t buf_size;
45089 u32 reset_flag;
45090
45091 memset(buf, 0, sizeof(buf));
45092@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45093 {
45094 struct iwl_priv *priv = file->private_data;
45095 char buf[8];
45096- int buf_size;
45097+ size_t buf_size;
45098 int ht40;
45099
45100 memset(buf, 0, sizeof(buf));
45101@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45102 {
45103 struct iwl_priv *priv = file->private_data;
45104 char buf[8];
45105- int buf_size;
45106+ size_t buf_size;
45107 int value;
45108
45109 memset(buf, 0, sizeof(buf));
45110@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45111 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45112 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45113
45114-static const char *fmt_value = " %-30s %10u\n";
45115-static const char *fmt_hex = " %-30s 0x%02X\n";
45116-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45117-static const char *fmt_header =
45118+static const char fmt_value[] = " %-30s %10u\n";
45119+static const char fmt_hex[] = " %-30s 0x%02X\n";
45120+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45121+static const char fmt_header[] =
45122 "%-32s current cumulative delta max\n";
45123
45124 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45125@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45126 {
45127 struct iwl_priv *priv = file->private_data;
45128 char buf[8];
45129- int buf_size;
45130+ size_t buf_size;
45131 int clear;
45132
45133 memset(buf, 0, sizeof(buf));
45134@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45135 {
45136 struct iwl_priv *priv = file->private_data;
45137 char buf[8];
45138- int buf_size;
45139+ size_t buf_size;
45140 int trace;
45141
45142 memset(buf, 0, sizeof(buf));
45143@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45144 {
45145 struct iwl_priv *priv = file->private_data;
45146 char buf[8];
45147- int buf_size;
45148+ size_t buf_size;
45149 int missed;
45150
45151 memset(buf, 0, sizeof(buf));
45152@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45153
45154 struct iwl_priv *priv = file->private_data;
45155 char buf[8];
45156- int buf_size;
45157+ size_t buf_size;
45158 int plcp;
45159
45160 memset(buf, 0, sizeof(buf));
45161@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45162
45163 struct iwl_priv *priv = file->private_data;
45164 char buf[8];
45165- int buf_size;
45166+ size_t buf_size;
45167 int flush;
45168
45169 memset(buf, 0, sizeof(buf));
45170@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45171
45172 struct iwl_priv *priv = file->private_data;
45173 char buf[8];
45174- int buf_size;
45175+ size_t buf_size;
45176 int rts;
45177
45178 if (!priv->cfg->ht_params)
45179@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45180 {
45181 struct iwl_priv *priv = file->private_data;
45182 char buf[8];
45183- int buf_size;
45184+ size_t buf_size;
45185
45186 memset(buf, 0, sizeof(buf));
45187 buf_size = min(count, sizeof(buf) - 1);
45188@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45189 struct iwl_priv *priv = file->private_data;
45190 u32 event_log_flag;
45191 char buf[8];
45192- int buf_size;
45193+ size_t buf_size;
45194
45195 /* check that the interface is up */
45196 if (!iwl_is_ready(priv))
45197@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45198 struct iwl_priv *priv = file->private_data;
45199 char buf[8];
45200 u32 calib_disabled;
45201- int buf_size;
45202+ size_t buf_size;
45203
45204 memset(buf, 0, sizeof(buf));
45205 buf_size = min(count, sizeof(buf) - 1);
45206diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45207index a8afc7b..de058b2 100644
45208--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45209+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45210@@ -1189,7 +1189,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45211 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45212 {
45213 struct iwl_nvm_data *data = priv->nvm_data;
45214- char *debug_msg;
45215+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45216
45217 if (data->sku_cap_11n_enable &&
45218 !priv->cfg->ht_params) {
45219@@ -1203,7 +1203,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45220 return -EINVAL;
45221 }
45222
45223- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45224 IWL_DEBUG_INFO(priv, debug_msg,
45225 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45226 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45227diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45228index aeb70e1..d7b5bb5 100644
45229--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45230+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45231@@ -1329,7 +1329,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45232 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45233
45234 char buf[8];
45235- int buf_size;
45236+ size_t buf_size;
45237 u32 reset_flag;
45238
45239 memset(buf, 0, sizeof(buf));
45240@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45241 {
45242 struct iwl_trans *trans = file->private_data;
45243 char buf[8];
45244- int buf_size;
45245+ size_t buf_size;
45246 int csr;
45247
45248 memset(buf, 0, sizeof(buf));
45249diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45250index cb34c78..9fec0dc 100644
45251--- a/drivers/net/wireless/mac80211_hwsim.c
45252+++ b/drivers/net/wireless/mac80211_hwsim.c
45253@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45254
45255 if (channels > 1) {
45256 hwsim_if_comb.num_different_channels = channels;
45257- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45258- mac80211_hwsim_ops.cancel_hw_scan =
45259- mac80211_hwsim_cancel_hw_scan;
45260- mac80211_hwsim_ops.sw_scan_start = NULL;
45261- mac80211_hwsim_ops.sw_scan_complete = NULL;
45262- mac80211_hwsim_ops.remain_on_channel =
45263- mac80211_hwsim_roc;
45264- mac80211_hwsim_ops.cancel_remain_on_channel =
45265- mac80211_hwsim_croc;
45266- mac80211_hwsim_ops.add_chanctx =
45267- mac80211_hwsim_add_chanctx;
45268- mac80211_hwsim_ops.remove_chanctx =
45269- mac80211_hwsim_remove_chanctx;
45270- mac80211_hwsim_ops.change_chanctx =
45271- mac80211_hwsim_change_chanctx;
45272- mac80211_hwsim_ops.assign_vif_chanctx =
45273- mac80211_hwsim_assign_vif_chanctx;
45274- mac80211_hwsim_ops.unassign_vif_chanctx =
45275- mac80211_hwsim_unassign_vif_chanctx;
45276+ pax_open_kernel();
45277+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45278+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45279+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45280+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45281+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45282+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45283+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45284+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45285+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45286+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45287+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45288+ pax_close_kernel();
45289 }
45290
45291 spin_lock_init(&hwsim_radio_lock);
45292diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45293index 8169a85..7fa3b47 100644
45294--- a/drivers/net/wireless/rndis_wlan.c
45295+++ b/drivers/net/wireless/rndis_wlan.c
45296@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45297
45298 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45299
45300- if (rts_threshold < 0 || rts_threshold > 2347)
45301+ if (rts_threshold > 2347)
45302 rts_threshold = 2347;
45303
45304 tmp = cpu_to_le32(rts_threshold);
45305diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45306index 7510723..5ba37f5 100644
45307--- a/drivers/net/wireless/rt2x00/rt2x00.h
45308+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45309@@ -386,7 +386,7 @@ struct rt2x00_intf {
45310 * for hardware which doesn't support hardware
45311 * sequence counting.
45312 */
45313- atomic_t seqno;
45314+ atomic_unchecked_t seqno;
45315 };
45316
45317 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45318diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45319index d955741..8730748 100644
45320--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45321+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45322@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45323 * sequence counter given by mac80211.
45324 */
45325 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45326- seqno = atomic_add_return(0x10, &intf->seqno);
45327+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45328 else
45329- seqno = atomic_read(&intf->seqno);
45330+ seqno = atomic_read_unchecked(&intf->seqno);
45331
45332 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45333 hdr->seq_ctrl |= cpu_to_le16(seqno);
45334diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45335index e2b3d9c..67a5184 100644
45336--- a/drivers/net/wireless/ti/wl1251/sdio.c
45337+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45338@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45339
45340 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45341
45342- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45343- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45344+ pax_open_kernel();
45345+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45346+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45347+ pax_close_kernel();
45348
45349 wl1251_info("using dedicated interrupt line");
45350 } else {
45351- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45352- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45353+ pax_open_kernel();
45354+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45355+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45356+ pax_close_kernel();
45357
45358 wl1251_info("using SDIO interrupt");
45359 }
45360diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45361index 1c627da..69f7d17 100644
45362--- a/drivers/net/wireless/ti/wl12xx/main.c
45363+++ b/drivers/net/wireless/ti/wl12xx/main.c
45364@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45365 sizeof(wl->conf.mem));
45366
45367 /* read data preparation is only needed by wl127x */
45368- wl->ops->prepare_read = wl127x_prepare_read;
45369+ pax_open_kernel();
45370+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45371+ pax_close_kernel();
45372
45373 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45374 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45375@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45376 sizeof(wl->conf.mem));
45377
45378 /* read data preparation is only needed by wl127x */
45379- wl->ops->prepare_read = wl127x_prepare_read;
45380+ pax_open_kernel();
45381+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45382+ pax_close_kernel();
45383
45384 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45385 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45386diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45387index 9fa692d..b31fee0 100644
45388--- a/drivers/net/wireless/ti/wl18xx/main.c
45389+++ b/drivers/net/wireless/ti/wl18xx/main.c
45390@@ -1687,8 +1687,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45391 }
45392
45393 if (!checksum_param) {
45394- wl18xx_ops.set_rx_csum = NULL;
45395- wl18xx_ops.init_vif = NULL;
45396+ pax_open_kernel();
45397+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45398+ *(void **)&wl18xx_ops.init_vif = NULL;
45399+ pax_close_kernel();
45400 }
45401
45402 /* Enable 11a Band only if we have 5G antennas */
45403diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45404index 7ef0b4a..ff65c28 100644
45405--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45406+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45407@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45408 {
45409 struct zd_usb *usb = urb->context;
45410 struct zd_usb_interrupt *intr = &usb->intr;
45411- int len;
45412+ unsigned int len;
45413 u16 int_num;
45414
45415 ZD_ASSERT(in_interrupt());
45416diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45417index d93b2b6..ae50401 100644
45418--- a/drivers/oprofile/buffer_sync.c
45419+++ b/drivers/oprofile/buffer_sync.c
45420@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45421 if (cookie == NO_COOKIE)
45422 offset = pc;
45423 if (cookie == INVALID_COOKIE) {
45424- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45425+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45426 offset = pc;
45427 }
45428 if (cookie != last_cookie) {
45429@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45430 /* add userspace sample */
45431
45432 if (!mm) {
45433- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45434+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45435 return 0;
45436 }
45437
45438 cookie = lookup_dcookie(mm, s->eip, &offset);
45439
45440 if (cookie == INVALID_COOKIE) {
45441- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45442+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45443 return 0;
45444 }
45445
45446@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45447 /* ignore backtraces if failed to add a sample */
45448 if (state == sb_bt_start) {
45449 state = sb_bt_ignore;
45450- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45451+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45452 }
45453 }
45454 release_mm(mm);
45455diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45456index c0cc4e7..44d4e54 100644
45457--- a/drivers/oprofile/event_buffer.c
45458+++ b/drivers/oprofile/event_buffer.c
45459@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45460 }
45461
45462 if (buffer_pos == buffer_size) {
45463- atomic_inc(&oprofile_stats.event_lost_overflow);
45464+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45465 return;
45466 }
45467
45468diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45469index ed2c3ec..deda85a 100644
45470--- a/drivers/oprofile/oprof.c
45471+++ b/drivers/oprofile/oprof.c
45472@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45473 if (oprofile_ops.switch_events())
45474 return;
45475
45476- atomic_inc(&oprofile_stats.multiplex_counter);
45477+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45478 start_switch_worker();
45479 }
45480
45481diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45482index 84a208d..d61b0a1 100644
45483--- a/drivers/oprofile/oprofile_files.c
45484+++ b/drivers/oprofile/oprofile_files.c
45485@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45486
45487 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45488
45489-static ssize_t timeout_read(struct file *file, char __user *buf,
45490+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45491 size_t count, loff_t *offset)
45492 {
45493 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45494diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45495index 917d28e..d62d981 100644
45496--- a/drivers/oprofile/oprofile_stats.c
45497+++ b/drivers/oprofile/oprofile_stats.c
45498@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45499 cpu_buf->sample_invalid_eip = 0;
45500 }
45501
45502- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45503- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45504- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45505- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45506- atomic_set(&oprofile_stats.multiplex_counter, 0);
45507+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45508+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45509+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45510+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45511+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45512 }
45513
45514
45515diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45516index 38b6fc0..b5cbfce 100644
45517--- a/drivers/oprofile/oprofile_stats.h
45518+++ b/drivers/oprofile/oprofile_stats.h
45519@@ -13,11 +13,11 @@
45520 #include <linux/atomic.h>
45521
45522 struct oprofile_stat_struct {
45523- atomic_t sample_lost_no_mm;
45524- atomic_t sample_lost_no_mapping;
45525- atomic_t bt_lost_no_mapping;
45526- atomic_t event_lost_overflow;
45527- atomic_t multiplex_counter;
45528+ atomic_unchecked_t sample_lost_no_mm;
45529+ atomic_unchecked_t sample_lost_no_mapping;
45530+ atomic_unchecked_t bt_lost_no_mapping;
45531+ atomic_unchecked_t event_lost_overflow;
45532+ atomic_unchecked_t multiplex_counter;
45533 };
45534
45535 extern struct oprofile_stat_struct oprofile_stats;
45536diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45537index 7c12d9c..558bf3bb 100644
45538--- a/drivers/oprofile/oprofilefs.c
45539+++ b/drivers/oprofile/oprofilefs.c
45540@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45541
45542
45543 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45544- char const *name, atomic_t *val)
45545+ char const *name, atomic_unchecked_t *val)
45546 {
45547 return __oprofilefs_create_file(sb, root, name,
45548 &atomic_ro_fops, 0444, val);
45549diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45550index 93404f7..4a313d8 100644
45551--- a/drivers/oprofile/timer_int.c
45552+++ b/drivers/oprofile/timer_int.c
45553@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
45554 return NOTIFY_OK;
45555 }
45556
45557-static struct notifier_block __refdata oprofile_cpu_notifier = {
45558+static struct notifier_block oprofile_cpu_notifier = {
45559 .notifier_call = oprofile_cpu_notify,
45560 };
45561
45562diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45563index 92ed045..62d39bd7 100644
45564--- a/drivers/parport/procfs.c
45565+++ b/drivers/parport/procfs.c
45566@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45567
45568 *ppos += len;
45569
45570- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45571+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45572 }
45573
45574 #ifdef CONFIG_PARPORT_1284
45575@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45576
45577 *ppos += len;
45578
45579- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45580+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45581 }
45582 #endif /* IEEE1284.3 support. */
45583
45584diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45585index c35e8ad..fc33beb 100644
45586--- a/drivers/pci/hotplug/acpiphp_ibm.c
45587+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45588@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45589 goto init_cleanup;
45590 }
45591
45592- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45593+ pax_open_kernel();
45594+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45595+ pax_close_kernel();
45596 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45597
45598 return retval;
45599diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45600index a6a71c4..c91097b 100644
45601--- a/drivers/pci/hotplug/cpcihp_generic.c
45602+++ b/drivers/pci/hotplug/cpcihp_generic.c
45603@@ -73,7 +73,6 @@ static u16 port;
45604 static unsigned int enum_bit;
45605 static u8 enum_mask;
45606
45607-static struct cpci_hp_controller_ops generic_hpc_ops;
45608 static struct cpci_hp_controller generic_hpc;
45609
45610 static int __init validate_parameters(void)
45611@@ -139,6 +138,10 @@ static int query_enum(void)
45612 return ((value & enum_mask) == enum_mask);
45613 }
45614
45615+static struct cpci_hp_controller_ops generic_hpc_ops = {
45616+ .query_enum = query_enum,
45617+};
45618+
45619 static int __init cpcihp_generic_init(void)
45620 {
45621 int status;
45622@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45623 pci_dev_put(dev);
45624
45625 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45626- generic_hpc_ops.query_enum = query_enum;
45627 generic_hpc.ops = &generic_hpc_ops;
45628
45629 status = cpci_hp_register_controller(&generic_hpc);
45630diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45631index 449b4bb..257e2e8 100644
45632--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45633+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45634@@ -59,7 +59,6 @@
45635 /* local variables */
45636 static bool debug;
45637 static bool poll;
45638-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45639 static struct cpci_hp_controller zt5550_hpc;
45640
45641 /* Primary cPCI bus bridge device */
45642@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45643 return 0;
45644 }
45645
45646+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45647+ .query_enum = zt5550_hc_query_enum,
45648+};
45649+
45650 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45651 {
45652 int status;
45653@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45654 dbg("returned from zt5550_hc_config");
45655
45656 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45657- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45658 zt5550_hpc.ops = &zt5550_hpc_ops;
45659 if(!poll) {
45660 zt5550_hpc.irq = hc_dev->irq;
45661 zt5550_hpc.irq_flags = IRQF_SHARED;
45662 zt5550_hpc.dev_id = hc_dev;
45663
45664- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45665- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45666- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45667+ pax_open_kernel();
45668+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45669+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45670+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45671+ pax_open_kernel();
45672 } else {
45673 info("using ENUM# polling mode");
45674 }
45675diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45676index 76ba8a1..20ca857 100644
45677--- a/drivers/pci/hotplug/cpqphp_nvram.c
45678+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45679@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45680
45681 void compaq_nvram_init (void __iomem *rom_start)
45682 {
45683+
45684+#ifndef CONFIG_PAX_KERNEXEC
45685 if (rom_start) {
45686 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45687 }
45688+#endif
45689+
45690 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45691
45692 /* initialize our int15 lock */
45693diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45694index ec20f74..c1d961e 100644
45695--- a/drivers/pci/hotplug/pci_hotplug_core.c
45696+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45697@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45698 return -EINVAL;
45699 }
45700
45701- slot->ops->owner = owner;
45702- slot->ops->mod_name = mod_name;
45703+ pax_open_kernel();
45704+ *(struct module **)&slot->ops->owner = owner;
45705+ *(const char **)&slot->ops->mod_name = mod_name;
45706+ pax_close_kernel();
45707
45708 mutex_lock(&pci_hp_mutex);
45709 /*
45710diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45711index 7d72c5e..edce02c 100644
45712--- a/drivers/pci/hotplug/pciehp_core.c
45713+++ b/drivers/pci/hotplug/pciehp_core.c
45714@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45715 struct slot *slot = ctrl->slot;
45716 struct hotplug_slot *hotplug = NULL;
45717 struct hotplug_slot_info *info = NULL;
45718- struct hotplug_slot_ops *ops = NULL;
45719+ hotplug_slot_ops_no_const *ops = NULL;
45720 char name[SLOT_NAME_SIZE];
45721 int retval = -ENOMEM;
45722
45723diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
45724index 5127f3f..b225573 100644
45725--- a/drivers/pci/hotplug/pciehp_hpc.c
45726+++ b/drivers/pci/hotplug/pciehp_hpc.c
45727@@ -773,14 +773,12 @@ static void pcie_shutdown_notification(struct controller *ctrl)
45728 static int pcie_init_slot(struct controller *ctrl)
45729 {
45730 struct slot *slot;
45731- char name[32];
45732
45733 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
45734 if (!slot)
45735 return -ENOMEM;
45736
45737- snprintf(name, sizeof(name), "pciehp-%u", PSN(ctrl));
45738- slot->wq = alloc_workqueue(name, 0, 0);
45739+ slot->wq = alloc_workqueue("pciehp-%u", 0, 0, PSN(ctrl));
45740 if (!slot->wq)
45741 goto abort;
45742
45743diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45744index 5b4a9d9..cd5ac1f 100644
45745--- a/drivers/pci/pci-sysfs.c
45746+++ b/drivers/pci/pci-sysfs.c
45747@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45748 {
45749 /* allocate attribute structure, piggyback attribute name */
45750 int name_len = write_combine ? 13 : 10;
45751- struct bin_attribute *res_attr;
45752+ bin_attribute_no_const *res_attr;
45753 int retval;
45754
45755 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45756@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45757 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45758 {
45759 int retval;
45760- struct bin_attribute *attr;
45761+ bin_attribute_no_const *attr;
45762
45763 /* If the device has VPD, try to expose it in sysfs. */
45764 if (dev->vpd) {
45765@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45766 {
45767 int retval;
45768 int rom_size = 0;
45769- struct bin_attribute *attr;
45770+ bin_attribute_no_const *attr;
45771
45772 if (!sysfs_initialized)
45773 return -EACCES;
45774diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45775index d1182c4..2a138ec 100644
45776--- a/drivers/pci/pci.h
45777+++ b/drivers/pci/pci.h
45778@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45779 struct pci_vpd {
45780 unsigned int len;
45781 const struct pci_vpd_ops *ops;
45782- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45783+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45784 };
45785
45786 int pci_vpd_pci22_init(struct pci_dev *dev);
45787diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45788index d320df6..ca9a8f6 100644
45789--- a/drivers/pci/pcie/aspm.c
45790+++ b/drivers/pci/pcie/aspm.c
45791@@ -27,9 +27,9 @@
45792 #define MODULE_PARAM_PREFIX "pcie_aspm."
45793
45794 /* Note: those are not register definitions */
45795-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45796-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45797-#define ASPM_STATE_L1 (4) /* L1 state */
45798+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45799+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45800+#define ASPM_STATE_L1 (4U) /* L1 state */
45801 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45802 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45803
45804diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45805index ea37072..10e58e56 100644
45806--- a/drivers/pci/probe.c
45807+++ b/drivers/pci/probe.c
45808@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45809 struct pci_bus_region region;
45810 bool bar_too_big = false, bar_disabled = false;
45811
45812- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45813+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45814
45815 /* No printks while decoding is disabled! */
45816 if (!dev->mmio_always_on) {
45817diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45818index 0812608..b04018c4 100644
45819--- a/drivers/pci/proc.c
45820+++ b/drivers/pci/proc.c
45821@@ -453,7 +453,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45822 static int __init pci_proc_init(void)
45823 {
45824 struct pci_dev *dev = NULL;
45825+
45826+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45827+#ifdef CONFIG_GRKERNSEC_PROC_USER
45828+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45829+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45830+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45831+#endif
45832+#else
45833 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45834+#endif
45835 proc_create("devices", 0, proc_bus_pci_dir,
45836 &proc_bus_pci_dev_operations);
45837 proc_initialized = 1;
45838diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45839index 3e5b4497..dcdfb70 100644
45840--- a/drivers/platform/x86/chromeos_laptop.c
45841+++ b/drivers/platform/x86/chromeos_laptop.c
45842@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45843 return 0;
45844 }
45845
45846-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45847+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45848 {
45849 .ident = "Samsung Series 5 550 - Touchpad",
45850 .matches = {
45851diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45852index 6b22938..bc9700e 100644
45853--- a/drivers/platform/x86/msi-laptop.c
45854+++ b/drivers/platform/x86/msi-laptop.c
45855@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45856
45857 if (!quirks->ec_read_only) {
45858 /* allow userland write sysfs file */
45859- dev_attr_bluetooth.store = store_bluetooth;
45860- dev_attr_wlan.store = store_wlan;
45861- dev_attr_threeg.store = store_threeg;
45862- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45863- dev_attr_wlan.attr.mode |= S_IWUSR;
45864- dev_attr_threeg.attr.mode |= S_IWUSR;
45865+ pax_open_kernel();
45866+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45867+ *(void **)&dev_attr_wlan.store = store_wlan;
45868+ *(void **)&dev_attr_threeg.store = store_threeg;
45869+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45870+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45871+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45872+ pax_close_kernel();
45873 }
45874
45875 /* disable hardware control by fn key */
45876diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45877index 2ac045f..39c443d 100644
45878--- a/drivers/platform/x86/sony-laptop.c
45879+++ b/drivers/platform/x86/sony-laptop.c
45880@@ -2483,7 +2483,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45881 }
45882
45883 /* High speed charging function */
45884-static struct device_attribute *hsc_handle;
45885+static device_attribute_no_const *hsc_handle;
45886
45887 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45888 struct device_attribute *attr,
45889diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45890index 54d31c0..3f896d3 100644
45891--- a/drivers/platform/x86/thinkpad_acpi.c
45892+++ b/drivers/platform/x86/thinkpad_acpi.c
45893@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45894 return 0;
45895 }
45896
45897-void static hotkey_mask_warn_incomplete_mask(void)
45898+static void hotkey_mask_warn_incomplete_mask(void)
45899 {
45900 /* log only what the user can fix... */
45901 const u32 wantedmask = hotkey_driver_mask &
45902@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45903 }
45904 }
45905
45906-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45907- struct tp_nvram_state *newn,
45908- const u32 event_mask)
45909-{
45910-
45911 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45912 do { \
45913 if ((event_mask & (1 << __scancode)) && \
45914@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45915 tpacpi_hotkey_send_key(__scancode); \
45916 } while (0)
45917
45918- void issue_volchange(const unsigned int oldvol,
45919- const unsigned int newvol)
45920- {
45921- unsigned int i = oldvol;
45922+static void issue_volchange(const unsigned int oldvol,
45923+ const unsigned int newvol,
45924+ const u32 event_mask)
45925+{
45926+ unsigned int i = oldvol;
45927
45928- while (i > newvol) {
45929- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45930- i--;
45931- }
45932- while (i < newvol) {
45933- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45934- i++;
45935- }
45936+ while (i > newvol) {
45937+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45938+ i--;
45939 }
45940+ while (i < newvol) {
45941+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45942+ i++;
45943+ }
45944+}
45945
45946- void issue_brightnesschange(const unsigned int oldbrt,
45947- const unsigned int newbrt)
45948- {
45949- unsigned int i = oldbrt;
45950+static void issue_brightnesschange(const unsigned int oldbrt,
45951+ const unsigned int newbrt,
45952+ const u32 event_mask)
45953+{
45954+ unsigned int i = oldbrt;
45955
45956- while (i > newbrt) {
45957- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45958- i--;
45959- }
45960- while (i < newbrt) {
45961- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45962- i++;
45963- }
45964+ while (i > newbrt) {
45965+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45966+ i--;
45967+ }
45968+ while (i < newbrt) {
45969+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45970+ i++;
45971 }
45972+}
45973
45974+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45975+ struct tp_nvram_state *newn,
45976+ const u32 event_mask)
45977+{
45978 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45979 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45980 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45981@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45982 oldn->volume_level != newn->volume_level) {
45983 /* recently muted, or repeated mute keypress, or
45984 * multiple presses ending in mute */
45985- issue_volchange(oldn->volume_level, newn->volume_level);
45986+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45987 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45988 }
45989 } else {
45990@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45991 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45992 }
45993 if (oldn->volume_level != newn->volume_level) {
45994- issue_volchange(oldn->volume_level, newn->volume_level);
45995+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45996 } else if (oldn->volume_toggle != newn->volume_toggle) {
45997 /* repeated vol up/down keypress at end of scale ? */
45998 if (newn->volume_level == 0)
45999@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46000 /* handle brightness */
46001 if (oldn->brightness_level != newn->brightness_level) {
46002 issue_brightnesschange(oldn->brightness_level,
46003- newn->brightness_level);
46004+ newn->brightness_level,
46005+ event_mask);
46006 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
46007 /* repeated key presses that didn't change state */
46008 if (newn->brightness_level == 0)
46009@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46010 && !tp_features.bright_unkfw)
46011 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46012 }
46013+}
46014
46015 #undef TPACPI_COMPARE_KEY
46016 #undef TPACPI_MAY_SEND_KEY
46017-}
46018
46019 /*
46020 * Polling driver
46021diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
46022index e4ac38a..b13344c 100644
46023--- a/drivers/platform/x86/wmi.c
46024+++ b/drivers/platform/x86/wmi.c
46025@@ -743,7 +743,7 @@ static int wmi_create_device(const struct guid_block *gblock,
46026 wblock->dev.class = &wmi_class;
46027
46028 wmi_gtoa(gblock->guid, guid_string);
46029- dev_set_name(&wblock->dev, guid_string);
46030+ dev_set_name(&wblock->dev, "%s", guid_string);
46031
46032 dev_set_drvdata(&wblock->dev, wblock);
46033
46034diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46035index 769d265..a3a05ca 100644
46036--- a/drivers/pnp/pnpbios/bioscalls.c
46037+++ b/drivers/pnp/pnpbios/bioscalls.c
46038@@ -58,7 +58,7 @@ do { \
46039 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46040 } while(0)
46041
46042-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46043+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46044 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46045
46046 /*
46047@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46048
46049 cpu = get_cpu();
46050 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
46051+
46052+ pax_open_kernel();
46053 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
46054+ pax_close_kernel();
46055
46056 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
46057 spin_lock_irqsave(&pnp_bios_lock, flags);
46058@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46059 :"memory");
46060 spin_unlock_irqrestore(&pnp_bios_lock, flags);
46061
46062+ pax_open_kernel();
46063 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46064+ pax_close_kernel();
46065+
46066 put_cpu();
46067
46068 /* If we get here and this is set then the PnP BIOS faulted on us. */
46069@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46070 return status;
46071 }
46072
46073-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46074+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46075 {
46076 int i;
46077
46078@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46079 pnp_bios_callpoint.offset = header->fields.pm16offset;
46080 pnp_bios_callpoint.segment = PNP_CS16;
46081
46082+ pax_open_kernel();
46083+
46084 for_each_possible_cpu(i) {
46085 struct desc_struct *gdt = get_cpu_gdt_table(i);
46086 if (!gdt)
46087@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46088 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46089 (unsigned long)__va(header->fields.pm16dseg));
46090 }
46091+
46092+ pax_close_kernel();
46093 }
46094diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46095index 3e6db1c..1fbbdae 100644
46096--- a/drivers/pnp/resource.c
46097+++ b/drivers/pnp/resource.c
46098@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46099 return 1;
46100
46101 /* check if the resource is valid */
46102- if (*irq < 0 || *irq > 15)
46103+ if (*irq > 15)
46104 return 0;
46105
46106 /* check if the resource is reserved */
46107@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46108 return 1;
46109
46110 /* check if the resource is valid */
46111- if (*dma < 0 || *dma == 4 || *dma > 7)
46112+ if (*dma == 4 || *dma > 7)
46113 return 0;
46114
46115 /* check if the resource is reserved */
46116diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46117index 0c52e2a..3421ab7 100644
46118--- a/drivers/power/pda_power.c
46119+++ b/drivers/power/pda_power.c
46120@@ -37,7 +37,11 @@ static int polling;
46121
46122 #if IS_ENABLED(CONFIG_USB_PHY)
46123 static struct usb_phy *transceiver;
46124-static struct notifier_block otg_nb;
46125+static int otg_handle_notification(struct notifier_block *nb,
46126+ unsigned long event, void *unused);
46127+static struct notifier_block otg_nb = {
46128+ .notifier_call = otg_handle_notification
46129+};
46130 #endif
46131
46132 static struct regulator *ac_draw;
46133@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46134
46135 #if IS_ENABLED(CONFIG_USB_PHY)
46136 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46137- otg_nb.notifier_call = otg_handle_notification;
46138 ret = usb_register_notifier(transceiver, &otg_nb);
46139 if (ret) {
46140 dev_err(dev, "failure to register otg notifier\n");
46141diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46142index cc439fd..8fa30df 100644
46143--- a/drivers/power/power_supply.h
46144+++ b/drivers/power/power_supply.h
46145@@ -16,12 +16,12 @@ struct power_supply;
46146
46147 #ifdef CONFIG_SYSFS
46148
46149-extern void power_supply_init_attrs(struct device_type *dev_type);
46150+extern void power_supply_init_attrs(void);
46151 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46152
46153 #else
46154
46155-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46156+static inline void power_supply_init_attrs(void) {}
46157 #define power_supply_uevent NULL
46158
46159 #endif /* CONFIG_SYSFS */
46160diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46161index 1c517c3..ffa2f17 100644
46162--- a/drivers/power/power_supply_core.c
46163+++ b/drivers/power/power_supply_core.c
46164@@ -24,7 +24,10 @@
46165 struct class *power_supply_class;
46166 EXPORT_SYMBOL_GPL(power_supply_class);
46167
46168-static struct device_type power_supply_dev_type;
46169+extern const struct attribute_group *power_supply_attr_groups[];
46170+static struct device_type power_supply_dev_type = {
46171+ .groups = power_supply_attr_groups,
46172+};
46173
46174 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46175 struct power_supply *supply)
46176@@ -554,7 +557,7 @@ static int __init power_supply_class_init(void)
46177 return PTR_ERR(power_supply_class);
46178
46179 power_supply_class->dev_uevent = power_supply_uevent;
46180- power_supply_init_attrs(&power_supply_dev_type);
46181+ power_supply_init_attrs();
46182
46183 return 0;
46184 }
46185diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46186index 29178f7..c65f324 100644
46187--- a/drivers/power/power_supply_sysfs.c
46188+++ b/drivers/power/power_supply_sysfs.c
46189@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46190 .is_visible = power_supply_attr_is_visible,
46191 };
46192
46193-static const struct attribute_group *power_supply_attr_groups[] = {
46194+const struct attribute_group *power_supply_attr_groups[] = {
46195 &power_supply_attr_group,
46196 NULL,
46197 };
46198
46199-void power_supply_init_attrs(struct device_type *dev_type)
46200+void power_supply_init_attrs(void)
46201 {
46202 int i;
46203
46204- dev_type->groups = power_supply_attr_groups;
46205-
46206 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46207 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46208 }
46209diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46210index 815d6df..811633a 100644
46211--- a/drivers/regulator/core.c
46212+++ b/drivers/regulator/core.c
46213@@ -3529,7 +3529,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46214 {
46215 const struct regulation_constraints *constraints = NULL;
46216 const struct regulator_init_data *init_data;
46217- static atomic_t regulator_no = ATOMIC_INIT(0);
46218+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46219 struct regulator_dev *rdev;
46220 struct device *dev;
46221 int ret, i;
46222@@ -3599,7 +3599,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46223 rdev->dev.of_node = config->of_node;
46224 rdev->dev.parent = dev;
46225 dev_set_name(&rdev->dev, "regulator.%d",
46226- atomic_inc_return(&regulator_no) - 1);
46227+ atomic_inc_return_unchecked(&regulator_no) - 1);
46228 ret = device_register(&rdev->dev);
46229 if (ret != 0) {
46230 put_device(&rdev->dev);
46231diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46232index d428ef9..fdc0357 100644
46233--- a/drivers/regulator/max8660.c
46234+++ b/drivers/regulator/max8660.c
46235@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
46236 max8660->shadow_regs[MAX8660_OVER1] = 5;
46237 } else {
46238 /* Otherwise devices can be toggled via software */
46239- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46240- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46241+ pax_open_kernel();
46242+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46243+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46244+ pax_close_kernel();
46245 }
46246
46247 /*
46248diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46249index adb1414..c13e0ce 100644
46250--- a/drivers/regulator/max8973-regulator.c
46251+++ b/drivers/regulator/max8973-regulator.c
46252@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
46253 if (!pdata->enable_ext_control) {
46254 max->desc.enable_reg = MAX8973_VOUT;
46255 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46256- max8973_dcdc_ops.enable = regulator_enable_regmap;
46257- max8973_dcdc_ops.disable = regulator_disable_regmap;
46258- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
46259+ pax_open_kernel();
46260+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
46261+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
46262+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
46263+ pax_close_kernel();
46264 }
46265
46266 max->enable_external_control = pdata->enable_ext_control;
46267diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46268index b716283..3cc4349 100644
46269--- a/drivers/regulator/mc13892-regulator.c
46270+++ b/drivers/regulator/mc13892-regulator.c
46271@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46272 }
46273 mc13xxx_unlock(mc13892);
46274
46275- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46276+ pax_open_kernel();
46277+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46278 = mc13892_vcam_set_mode;
46279- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46280+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46281 = mc13892_vcam_get_mode;
46282+ pax_close_kernel();
46283
46284 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46285 ARRAY_SIZE(mc13892_regulators));
46286diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46287index f1cb706..4c7832a 100644
46288--- a/drivers/rtc/rtc-cmos.c
46289+++ b/drivers/rtc/rtc-cmos.c
46290@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46291 hpet_rtc_timer_init();
46292
46293 /* export at least the first block of NVRAM */
46294- nvram.size = address_space - NVRAM_OFFSET;
46295+ pax_open_kernel();
46296+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46297+ pax_close_kernel();
46298 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46299 if (retval < 0) {
46300 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46301diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46302index d049393..bb20be0 100644
46303--- a/drivers/rtc/rtc-dev.c
46304+++ b/drivers/rtc/rtc-dev.c
46305@@ -16,6 +16,7 @@
46306 #include <linux/module.h>
46307 #include <linux/rtc.h>
46308 #include <linux/sched.h>
46309+#include <linux/grsecurity.h>
46310 #include "rtc-core.h"
46311
46312 static dev_t rtc_devt;
46313@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46314 if (copy_from_user(&tm, uarg, sizeof(tm)))
46315 return -EFAULT;
46316
46317+ gr_log_timechange();
46318+
46319 return rtc_set_time(rtc, &tm);
46320
46321 case RTC_PIE_ON:
46322diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46323index b53992a..776df84 100644
46324--- a/drivers/rtc/rtc-ds1307.c
46325+++ b/drivers/rtc/rtc-ds1307.c
46326@@ -107,7 +107,7 @@ struct ds1307 {
46327 u8 offset; /* register's offset */
46328 u8 regs[11];
46329 u16 nvram_offset;
46330- struct bin_attribute *nvram;
46331+ bin_attribute_no_const *nvram;
46332 enum ds_type type;
46333 unsigned long flags;
46334 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46335diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46336index 130f29a..6179d03 100644
46337--- a/drivers/rtc/rtc-m48t59.c
46338+++ b/drivers/rtc/rtc-m48t59.c
46339@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46340 goto out;
46341 }
46342
46343- m48t59_nvram_attr.size = pdata->offset;
46344+ pax_open_kernel();
46345+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46346+ pax_close_kernel();
46347
46348 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46349 if (ret) {
46350diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46351index e693af6..2e525b6 100644
46352--- a/drivers/scsi/bfa/bfa_fcpim.h
46353+++ b/drivers/scsi/bfa/bfa_fcpim.h
46354@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46355
46356 struct bfa_itn_s {
46357 bfa_isr_func_t isr;
46358-};
46359+} __no_const;
46360
46361 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46362 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46363diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46364index 23a90e7..9cf04ee 100644
46365--- a/drivers/scsi/bfa/bfa_ioc.h
46366+++ b/drivers/scsi/bfa/bfa_ioc.h
46367@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46368 bfa_ioc_disable_cbfn_t disable_cbfn;
46369 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46370 bfa_ioc_reset_cbfn_t reset_cbfn;
46371-};
46372+} __no_const;
46373
46374 /*
46375 * IOC event notification mechanism.
46376@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
46377 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
46378 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
46379 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
46380-};
46381+} __no_const;
46382
46383 /*
46384 * Queue element to wait for room in request queue. FIFO order is
46385diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46386index 8c05ae01..b2cf224 100644
46387--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46388+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46389@@ -33,8 +33,8 @@
46390 */
46391 #include "libfcoe.h"
46392
46393-static atomic_t ctlr_num;
46394-static atomic_t fcf_num;
46395+static atomic_unchecked_t ctlr_num;
46396+static atomic_unchecked_t fcf_num;
46397
46398 /*
46399 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46400@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46401 if (!ctlr)
46402 goto out;
46403
46404- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46405+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46406 ctlr->f = f;
46407 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46408 INIT_LIST_HEAD(&ctlr->fcfs);
46409@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46410 fcf->dev.parent = &ctlr->dev;
46411 fcf->dev.bus = &fcoe_bus_type;
46412 fcf->dev.type = &fcoe_fcf_device_type;
46413- fcf->id = atomic_inc_return(&fcf_num) - 1;
46414+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46415 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46416
46417 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46418@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46419 {
46420 int error;
46421
46422- atomic_set(&ctlr_num, 0);
46423- atomic_set(&fcf_num, 0);
46424+ atomic_set_unchecked(&ctlr_num, 0);
46425+ atomic_set_unchecked(&fcf_num, 0);
46426
46427 error = bus_register(&fcoe_bus_type);
46428 if (error)
46429diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46430index df0c3c7..b00e1d0 100644
46431--- a/drivers/scsi/hosts.c
46432+++ b/drivers/scsi/hosts.c
46433@@ -42,7 +42,7 @@
46434 #include "scsi_logging.h"
46435
46436
46437-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46438+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46439
46440
46441 static void scsi_host_cls_release(struct device *dev)
46442@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46443 * subtract one because we increment first then return, but we need to
46444 * know what the next host number was before increment
46445 */
46446- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46447+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46448 shost->dma_channel = 0xff;
46449
46450 /* These three are default values which can be overridden */
46451diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46452index 7f4f790..b75b92a 100644
46453--- a/drivers/scsi/hpsa.c
46454+++ b/drivers/scsi/hpsa.c
46455@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46456 unsigned long flags;
46457
46458 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46459- return h->access.command_completed(h, q);
46460+ return h->access->command_completed(h, q);
46461
46462 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46463 a = rq->head[rq->current_entry];
46464@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46465 while (!list_empty(&h->reqQ)) {
46466 c = list_entry(h->reqQ.next, struct CommandList, list);
46467 /* can't do anything if fifo is full */
46468- if ((h->access.fifo_full(h))) {
46469+ if ((h->access->fifo_full(h))) {
46470 dev_warn(&h->pdev->dev, "fifo full\n");
46471 break;
46472 }
46473@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46474
46475 /* Tell the controller execute command */
46476 spin_unlock_irqrestore(&h->lock, flags);
46477- h->access.submit_command(h, c);
46478+ h->access->submit_command(h, c);
46479 spin_lock_irqsave(&h->lock, flags);
46480 }
46481 spin_unlock_irqrestore(&h->lock, flags);
46482@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46483
46484 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46485 {
46486- return h->access.command_completed(h, q);
46487+ return h->access->command_completed(h, q);
46488 }
46489
46490 static inline bool interrupt_pending(struct ctlr_info *h)
46491 {
46492- return h->access.intr_pending(h);
46493+ return h->access->intr_pending(h);
46494 }
46495
46496 static inline long interrupt_not_for_us(struct ctlr_info *h)
46497 {
46498- return (h->access.intr_pending(h) == 0) ||
46499+ return (h->access->intr_pending(h) == 0) ||
46500 (h->interrupts_enabled == 0);
46501 }
46502
46503@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46504 if (prod_index < 0)
46505 return -ENODEV;
46506 h->product_name = products[prod_index].product_name;
46507- h->access = *(products[prod_index].access);
46508+ h->access = products[prod_index].access;
46509
46510 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46511 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46512@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46513
46514 assert_spin_locked(&lockup_detector_lock);
46515 remove_ctlr_from_lockup_detector_list(h);
46516- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46517+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46518 spin_lock_irqsave(&h->lock, flags);
46519 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46520 spin_unlock_irqrestore(&h->lock, flags);
46521@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46522 }
46523
46524 /* make sure the board interrupts are off */
46525- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46526+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46527
46528 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46529 goto clean2;
46530@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46531 * fake ones to scoop up any residual completions.
46532 */
46533 spin_lock_irqsave(&h->lock, flags);
46534- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46535+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46536 spin_unlock_irqrestore(&h->lock, flags);
46537 free_irqs(h);
46538 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46539@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46540 dev_info(&h->pdev->dev, "Board READY.\n");
46541 dev_info(&h->pdev->dev,
46542 "Waiting for stale completions to drain.\n");
46543- h->access.set_intr_mask(h, HPSA_INTR_ON);
46544+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46545 msleep(10000);
46546- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46547+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46548
46549 rc = controller_reset_failed(h->cfgtable);
46550 if (rc)
46551@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46552 }
46553
46554 /* Turn the interrupts on so we can service requests */
46555- h->access.set_intr_mask(h, HPSA_INTR_ON);
46556+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46557
46558 hpsa_hba_inquiry(h);
46559 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46560@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46561 * To write all data in the battery backed cache to disks
46562 */
46563 hpsa_flush_cache(h);
46564- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46565+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46566 hpsa_free_irqs_and_disable_msix(h);
46567 }
46568
46569@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46570 return;
46571 }
46572 /* Change the access methods to the performant access methods */
46573- h->access = SA5_performant_access;
46574+ h->access = &SA5_performant_access;
46575 h->transMethod = CFGTBL_Trans_Performant;
46576 }
46577
46578diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46579index 9816479..c5d4e97 100644
46580--- a/drivers/scsi/hpsa.h
46581+++ b/drivers/scsi/hpsa.h
46582@@ -79,7 +79,7 @@ struct ctlr_info {
46583 unsigned int msix_vector;
46584 unsigned int msi_vector;
46585 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46586- struct access_method access;
46587+ struct access_method *access;
46588
46589 /* queue and queue Info */
46590 struct list_head reqQ;
46591diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46592index 8b928c6..9c76300 100644
46593--- a/drivers/scsi/libfc/fc_exch.c
46594+++ b/drivers/scsi/libfc/fc_exch.c
46595@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46596 u16 pool_max_index;
46597
46598 struct {
46599- atomic_t no_free_exch;
46600- atomic_t no_free_exch_xid;
46601- atomic_t xid_not_found;
46602- atomic_t xid_busy;
46603- atomic_t seq_not_found;
46604- atomic_t non_bls_resp;
46605+ atomic_unchecked_t no_free_exch;
46606+ atomic_unchecked_t no_free_exch_xid;
46607+ atomic_unchecked_t xid_not_found;
46608+ atomic_unchecked_t xid_busy;
46609+ atomic_unchecked_t seq_not_found;
46610+ atomic_unchecked_t non_bls_resp;
46611 } stats;
46612 };
46613
46614@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46615 /* allocate memory for exchange */
46616 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46617 if (!ep) {
46618- atomic_inc(&mp->stats.no_free_exch);
46619+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46620 goto out;
46621 }
46622 memset(ep, 0, sizeof(*ep));
46623@@ -797,7 +797,7 @@ out:
46624 return ep;
46625 err:
46626 spin_unlock_bh(&pool->lock);
46627- atomic_inc(&mp->stats.no_free_exch_xid);
46628+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46629 mempool_free(ep, mp->ep_pool);
46630 return NULL;
46631 }
46632@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46633 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46634 ep = fc_exch_find(mp, xid);
46635 if (!ep) {
46636- atomic_inc(&mp->stats.xid_not_found);
46637+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46638 reject = FC_RJT_OX_ID;
46639 goto out;
46640 }
46641@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46642 ep = fc_exch_find(mp, xid);
46643 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46644 if (ep) {
46645- atomic_inc(&mp->stats.xid_busy);
46646+ atomic_inc_unchecked(&mp->stats.xid_busy);
46647 reject = FC_RJT_RX_ID;
46648 goto rel;
46649 }
46650@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46651 }
46652 xid = ep->xid; /* get our XID */
46653 } else if (!ep) {
46654- atomic_inc(&mp->stats.xid_not_found);
46655+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46656 reject = FC_RJT_RX_ID; /* XID not found */
46657 goto out;
46658 }
46659@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46660 } else {
46661 sp = &ep->seq;
46662 if (sp->id != fh->fh_seq_id) {
46663- atomic_inc(&mp->stats.seq_not_found);
46664+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46665 if (f_ctl & FC_FC_END_SEQ) {
46666 /*
46667 * Update sequence_id based on incoming last
46668@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46669
46670 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46671 if (!ep) {
46672- atomic_inc(&mp->stats.xid_not_found);
46673+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46674 goto out;
46675 }
46676 if (ep->esb_stat & ESB_ST_COMPLETE) {
46677- atomic_inc(&mp->stats.xid_not_found);
46678+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46679 goto rel;
46680 }
46681 if (ep->rxid == FC_XID_UNKNOWN)
46682 ep->rxid = ntohs(fh->fh_rx_id);
46683 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46684- atomic_inc(&mp->stats.xid_not_found);
46685+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46686 goto rel;
46687 }
46688 if (ep->did != ntoh24(fh->fh_s_id) &&
46689 ep->did != FC_FID_FLOGI) {
46690- atomic_inc(&mp->stats.xid_not_found);
46691+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46692 goto rel;
46693 }
46694 sof = fr_sof(fp);
46695@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46696 sp->ssb_stat |= SSB_ST_RESP;
46697 sp->id = fh->fh_seq_id;
46698 } else if (sp->id != fh->fh_seq_id) {
46699- atomic_inc(&mp->stats.seq_not_found);
46700+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46701 goto rel;
46702 }
46703
46704@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46705 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46706
46707 if (!sp)
46708- atomic_inc(&mp->stats.xid_not_found);
46709+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46710 else
46711- atomic_inc(&mp->stats.non_bls_resp);
46712+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46713
46714 fc_frame_free(fp);
46715 }
46716@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46717
46718 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46719 mp = ema->mp;
46720- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46721+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46722 st->fc_no_free_exch_xid +=
46723- atomic_read(&mp->stats.no_free_exch_xid);
46724- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46725- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46726- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46727- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46728+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46729+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46730+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46731+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46732+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46733 }
46734 }
46735 EXPORT_SYMBOL(fc_exch_update_stats);
46736diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46737index 161c98e..6d563b3 100644
46738--- a/drivers/scsi/libsas/sas_ata.c
46739+++ b/drivers/scsi/libsas/sas_ata.c
46740@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46741 .postreset = ata_std_postreset,
46742 .error_handler = ata_std_error_handler,
46743 .post_internal_cmd = sas_ata_post_internal,
46744- .qc_defer = ata_std_qc_defer,
46745+ .qc_defer = ata_std_qc_defer,
46746 .qc_prep = ata_noop_qc_prep,
46747 .qc_issue = sas_ata_qc_issue,
46748 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46749diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46750index bcc56ca..6f4174a 100644
46751--- a/drivers/scsi/lpfc/lpfc.h
46752+++ b/drivers/scsi/lpfc/lpfc.h
46753@@ -431,7 +431,7 @@ struct lpfc_vport {
46754 struct dentry *debug_nodelist;
46755 struct dentry *vport_debugfs_root;
46756 struct lpfc_debugfs_trc *disc_trc;
46757- atomic_t disc_trc_cnt;
46758+ atomic_unchecked_t disc_trc_cnt;
46759 #endif
46760 uint8_t stat_data_enabled;
46761 uint8_t stat_data_blocked;
46762@@ -865,8 +865,8 @@ struct lpfc_hba {
46763 struct timer_list fabric_block_timer;
46764 unsigned long bit_flags;
46765 #define FABRIC_COMANDS_BLOCKED 0
46766- atomic_t num_rsrc_err;
46767- atomic_t num_cmd_success;
46768+ atomic_unchecked_t num_rsrc_err;
46769+ atomic_unchecked_t num_cmd_success;
46770 unsigned long last_rsrc_error_time;
46771 unsigned long last_ramp_down_time;
46772 unsigned long last_ramp_up_time;
46773@@ -902,7 +902,7 @@ struct lpfc_hba {
46774
46775 struct dentry *debug_slow_ring_trc;
46776 struct lpfc_debugfs_trc *slow_ring_trc;
46777- atomic_t slow_ring_trc_cnt;
46778+ atomic_unchecked_t slow_ring_trc_cnt;
46779 /* iDiag debugfs sub-directory */
46780 struct dentry *idiag_root;
46781 struct dentry *idiag_pci_cfg;
46782diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46783index f525ecb..32549a4 100644
46784--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46785+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46786@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46787
46788 #include <linux/debugfs.h>
46789
46790-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46791+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46792 static unsigned long lpfc_debugfs_start_time = 0L;
46793
46794 /* iDiag */
46795@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46796 lpfc_debugfs_enable = 0;
46797
46798 len = 0;
46799- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46800+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46801 (lpfc_debugfs_max_disc_trc - 1);
46802 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46803 dtp = vport->disc_trc + i;
46804@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46805 lpfc_debugfs_enable = 0;
46806
46807 len = 0;
46808- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46809+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46810 (lpfc_debugfs_max_slow_ring_trc - 1);
46811 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46812 dtp = phba->slow_ring_trc + i;
46813@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46814 !vport || !vport->disc_trc)
46815 return;
46816
46817- index = atomic_inc_return(&vport->disc_trc_cnt) &
46818+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46819 (lpfc_debugfs_max_disc_trc - 1);
46820 dtp = vport->disc_trc + index;
46821 dtp->fmt = fmt;
46822 dtp->data1 = data1;
46823 dtp->data2 = data2;
46824 dtp->data3 = data3;
46825- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46826+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46827 dtp->jif = jiffies;
46828 #endif
46829 return;
46830@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46831 !phba || !phba->slow_ring_trc)
46832 return;
46833
46834- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46835+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46836 (lpfc_debugfs_max_slow_ring_trc - 1);
46837 dtp = phba->slow_ring_trc + index;
46838 dtp->fmt = fmt;
46839 dtp->data1 = data1;
46840 dtp->data2 = data2;
46841 dtp->data3 = data3;
46842- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46843+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46844 dtp->jif = jiffies;
46845 #endif
46846 return;
46847@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46848 "slow_ring buffer\n");
46849 goto debug_failed;
46850 }
46851- atomic_set(&phba->slow_ring_trc_cnt, 0);
46852+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46853 memset(phba->slow_ring_trc, 0,
46854 (sizeof(struct lpfc_debugfs_trc) *
46855 lpfc_debugfs_max_slow_ring_trc));
46856@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46857 "buffer\n");
46858 goto debug_failed;
46859 }
46860- atomic_set(&vport->disc_trc_cnt, 0);
46861+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46862
46863 snprintf(name, sizeof(name), "discovery_trace");
46864 vport->debug_disc_trc =
46865diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46866index cb465b2..2e7b25f 100644
46867--- a/drivers/scsi/lpfc/lpfc_init.c
46868+++ b/drivers/scsi/lpfc/lpfc_init.c
46869@@ -10950,8 +10950,10 @@ lpfc_init(void)
46870 "misc_register returned with status %d", error);
46871
46872 if (lpfc_enable_npiv) {
46873- lpfc_transport_functions.vport_create = lpfc_vport_create;
46874- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46875+ pax_open_kernel();
46876+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46877+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46878+ pax_close_kernel();
46879 }
46880 lpfc_transport_template =
46881 fc_attach_transport(&lpfc_transport_functions);
46882diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46883index 8523b278e..ce1d812 100644
46884--- a/drivers/scsi/lpfc/lpfc_scsi.c
46885+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46886@@ -331,7 +331,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46887 uint32_t evt_posted;
46888
46889 spin_lock_irqsave(&phba->hbalock, flags);
46890- atomic_inc(&phba->num_rsrc_err);
46891+ atomic_inc_unchecked(&phba->num_rsrc_err);
46892 phba->last_rsrc_error_time = jiffies;
46893
46894 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46895@@ -372,7 +372,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46896 unsigned long flags;
46897 struct lpfc_hba *phba = vport->phba;
46898 uint32_t evt_posted;
46899- atomic_inc(&phba->num_cmd_success);
46900+ atomic_inc_unchecked(&phba->num_cmd_success);
46901
46902 if (vport->cfg_lun_queue_depth <= queue_depth)
46903 return;
46904@@ -416,8 +416,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46905 unsigned long num_rsrc_err, num_cmd_success;
46906 int i;
46907
46908- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46909- num_cmd_success = atomic_read(&phba->num_cmd_success);
46910+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46911+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46912
46913 /*
46914 * The error and success command counters are global per
46915@@ -445,8 +445,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46916 }
46917 }
46918 lpfc_destroy_vport_work_array(phba, vports);
46919- atomic_set(&phba->num_rsrc_err, 0);
46920- atomic_set(&phba->num_cmd_success, 0);
46921+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46922+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46923 }
46924
46925 /**
46926@@ -480,8 +480,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46927 }
46928 }
46929 lpfc_destroy_vport_work_array(phba, vports);
46930- atomic_set(&phba->num_rsrc_err, 0);
46931- atomic_set(&phba->num_cmd_success, 0);
46932+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46933+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46934 }
46935
46936 /**
46937diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46938index 8e1b737..50ff510 100644
46939--- a/drivers/scsi/pmcraid.c
46940+++ b/drivers/scsi/pmcraid.c
46941@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46942 res->scsi_dev = scsi_dev;
46943 scsi_dev->hostdata = res;
46944 res->change_detected = 0;
46945- atomic_set(&res->read_failures, 0);
46946- atomic_set(&res->write_failures, 0);
46947+ atomic_set_unchecked(&res->read_failures, 0);
46948+ atomic_set_unchecked(&res->write_failures, 0);
46949 rc = 0;
46950 }
46951 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46952@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46953
46954 /* If this was a SCSI read/write command keep count of errors */
46955 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46956- atomic_inc(&res->read_failures);
46957+ atomic_inc_unchecked(&res->read_failures);
46958 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46959- atomic_inc(&res->write_failures);
46960+ atomic_inc_unchecked(&res->write_failures);
46961
46962 if (!RES_IS_GSCSI(res->cfg_entry) &&
46963 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46964@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46965 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46966 * hrrq_id assigned here in queuecommand
46967 */
46968- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46969+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46970 pinstance->num_hrrq;
46971 cmd->cmd_done = pmcraid_io_done;
46972
46973@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46974 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46975 * hrrq_id assigned here in queuecommand
46976 */
46977- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46978+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46979 pinstance->num_hrrq;
46980
46981 if (request_size) {
46982@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46983
46984 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46985 /* add resources only after host is added into system */
46986- if (!atomic_read(&pinstance->expose_resources))
46987+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46988 return;
46989
46990 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46991@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46992 init_waitqueue_head(&pinstance->reset_wait_q);
46993
46994 atomic_set(&pinstance->outstanding_cmds, 0);
46995- atomic_set(&pinstance->last_message_id, 0);
46996- atomic_set(&pinstance->expose_resources, 0);
46997+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46998+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46999
47000 INIT_LIST_HEAD(&pinstance->free_res_q);
47001 INIT_LIST_HEAD(&pinstance->used_res_q);
47002@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
47003 /* Schedule worker thread to handle CCN and take care of adding and
47004 * removing devices to OS
47005 */
47006- atomic_set(&pinstance->expose_resources, 1);
47007+ atomic_set_unchecked(&pinstance->expose_resources, 1);
47008 schedule_work(&pinstance->worker_q);
47009 return rc;
47010
47011diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
47012index e1d150f..6c6df44 100644
47013--- a/drivers/scsi/pmcraid.h
47014+++ b/drivers/scsi/pmcraid.h
47015@@ -748,7 +748,7 @@ struct pmcraid_instance {
47016 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
47017
47018 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
47019- atomic_t last_message_id;
47020+ atomic_unchecked_t last_message_id;
47021
47022 /* configuration table */
47023 struct pmcraid_config_table *cfg_table;
47024@@ -777,7 +777,7 @@ struct pmcraid_instance {
47025 atomic_t outstanding_cmds;
47026
47027 /* should add/delete resources to mid-layer now ?*/
47028- atomic_t expose_resources;
47029+ atomic_unchecked_t expose_resources;
47030
47031
47032
47033@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
47034 struct pmcraid_config_table_entry_ext cfg_entry_ext;
47035 };
47036 struct scsi_device *scsi_dev; /* Link scsi_device structure */
47037- atomic_t read_failures; /* count of failed READ commands */
47038- atomic_t write_failures; /* count of failed WRITE commands */
47039+ atomic_unchecked_t read_failures; /* count of failed READ commands */
47040+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
47041
47042 /* To indicate add/delete/modify during CCN */
47043 u8 change_detected;
47044diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
47045index bf60c63..74d4dce 100644
47046--- a/drivers/scsi/qla2xxx/qla_attr.c
47047+++ b/drivers/scsi/qla2xxx/qla_attr.c
47048@@ -2001,7 +2001,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
47049 return 0;
47050 }
47051
47052-struct fc_function_template qla2xxx_transport_functions = {
47053+fc_function_template_no_const qla2xxx_transport_functions = {
47054
47055 .show_host_node_name = 1,
47056 .show_host_port_name = 1,
47057@@ -2048,7 +2048,7 @@ struct fc_function_template qla2xxx_transport_functions = {
47058 .bsg_timeout = qla24xx_bsg_timeout,
47059 };
47060
47061-struct fc_function_template qla2xxx_transport_vport_functions = {
47062+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47063
47064 .show_host_node_name = 1,
47065 .show_host_port_name = 1,
47066diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47067index 026bfde..90c4018 100644
47068--- a/drivers/scsi/qla2xxx/qla_gbl.h
47069+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47070@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47071 struct device_attribute;
47072 extern struct device_attribute *qla2x00_host_attrs[];
47073 struct fc_function_template;
47074-extern struct fc_function_template qla2xxx_transport_functions;
47075-extern struct fc_function_template qla2xxx_transport_vport_functions;
47076+extern fc_function_template_no_const qla2xxx_transport_functions;
47077+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47078 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47079 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47080 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47081diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47082index ad72c1d..afc9a98 100644
47083--- a/drivers/scsi/qla2xxx/qla_os.c
47084+++ b/drivers/scsi/qla2xxx/qla_os.c
47085@@ -1571,8 +1571,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47086 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47087 /* Ok, a 64bit DMA mask is applicable. */
47088 ha->flags.enable_64bit_addressing = 1;
47089- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47090- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47091+ pax_open_kernel();
47092+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47093+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47094+ pax_close_kernel();
47095 return;
47096 }
47097 }
47098diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47099index ddf16a8..80f4dd0 100644
47100--- a/drivers/scsi/qla4xxx/ql4_def.h
47101+++ b/drivers/scsi/qla4xxx/ql4_def.h
47102@@ -291,7 +291,7 @@ struct ddb_entry {
47103 * (4000 only) */
47104 atomic_t relogin_timer; /* Max Time to wait for
47105 * relogin to complete */
47106- atomic_t relogin_retry_count; /* Num of times relogin has been
47107+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47108 * retried */
47109 uint32_t default_time2wait; /* Default Min time between
47110 * relogins (+aens) */
47111diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47112index 4d231c1..2892c37 100644
47113--- a/drivers/scsi/qla4xxx/ql4_os.c
47114+++ b/drivers/scsi/qla4xxx/ql4_os.c
47115@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47116 */
47117 if (!iscsi_is_session_online(cls_sess)) {
47118 /* Reset retry relogin timer */
47119- atomic_inc(&ddb_entry->relogin_retry_count);
47120+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47121 DEBUG2(ql4_printk(KERN_INFO, ha,
47122 "%s: index[%d] relogin timed out-retrying"
47123 " relogin (%d), retry (%d)\n", __func__,
47124 ddb_entry->fw_ddb_index,
47125- atomic_read(&ddb_entry->relogin_retry_count),
47126+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47127 ddb_entry->default_time2wait + 4));
47128 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47129 atomic_set(&ddb_entry->retry_relogin_timer,
47130@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47131
47132 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47133 atomic_set(&ddb_entry->relogin_timer, 0);
47134- atomic_set(&ddb_entry->relogin_retry_count, 0);
47135+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47136 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47137 ddb_entry->default_relogin_timeout =
47138 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47139diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47140index eaa808e..95f8841 100644
47141--- a/drivers/scsi/scsi.c
47142+++ b/drivers/scsi/scsi.c
47143@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47144 unsigned long timeout;
47145 int rtn = 0;
47146
47147- atomic_inc(&cmd->device->iorequest_cnt);
47148+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47149
47150 /* check if the device is still usable */
47151 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47152diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47153index 86d5220..f22c51a 100644
47154--- a/drivers/scsi/scsi_lib.c
47155+++ b/drivers/scsi/scsi_lib.c
47156@@ -1458,7 +1458,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47157 shost = sdev->host;
47158 scsi_init_cmd_errh(cmd);
47159 cmd->result = DID_NO_CONNECT << 16;
47160- atomic_inc(&cmd->device->iorequest_cnt);
47161+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47162
47163 /*
47164 * SCSI request completion path will do scsi_device_unbusy(),
47165@@ -1484,9 +1484,9 @@ static void scsi_softirq_done(struct request *rq)
47166
47167 INIT_LIST_HEAD(&cmd->eh_entry);
47168
47169- atomic_inc(&cmd->device->iodone_cnt);
47170+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47171 if (cmd->result)
47172- atomic_inc(&cmd->device->ioerr_cnt);
47173+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47174
47175 disposition = scsi_decide_disposition(cmd);
47176 if (disposition != SUCCESS &&
47177diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47178index 931a7d9..0c2a754 100644
47179--- a/drivers/scsi/scsi_sysfs.c
47180+++ b/drivers/scsi/scsi_sysfs.c
47181@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47182 char *buf) \
47183 { \
47184 struct scsi_device *sdev = to_scsi_device(dev); \
47185- unsigned long long count = atomic_read(&sdev->field); \
47186+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47187 return snprintf(buf, 20, "0x%llx\n", count); \
47188 } \
47189 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47190diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47191index 84a1fdf..693b0d6 100644
47192--- a/drivers/scsi/scsi_tgt_lib.c
47193+++ b/drivers/scsi/scsi_tgt_lib.c
47194@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47195 int err;
47196
47197 dprintk("%lx %u\n", uaddr, len);
47198- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47199+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47200 if (err) {
47201 /*
47202 * TODO: need to fixup sg_tablesize, max_segment_size,
47203diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47204index e106c27..11a380e 100644
47205--- a/drivers/scsi/scsi_transport_fc.c
47206+++ b/drivers/scsi/scsi_transport_fc.c
47207@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47208 * Netlink Infrastructure
47209 */
47210
47211-static atomic_t fc_event_seq;
47212+static atomic_unchecked_t fc_event_seq;
47213
47214 /**
47215 * fc_get_event_number - Obtain the next sequential FC event number
47216@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47217 u32
47218 fc_get_event_number(void)
47219 {
47220- return atomic_add_return(1, &fc_event_seq);
47221+ return atomic_add_return_unchecked(1, &fc_event_seq);
47222 }
47223 EXPORT_SYMBOL(fc_get_event_number);
47224
47225@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47226 {
47227 int error;
47228
47229- atomic_set(&fc_event_seq, 0);
47230+ atomic_set_unchecked(&fc_event_seq, 0);
47231
47232 error = transport_class_register(&fc_host_class);
47233 if (error)
47234@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47235 char *cp;
47236
47237 *val = simple_strtoul(buf, &cp, 0);
47238- if ((*cp && (*cp != '\n')) || (*val < 0))
47239+ if (*cp && (*cp != '\n'))
47240 return -EINVAL;
47241 /*
47242 * Check for overflow; dev_loss_tmo is u32
47243diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47244index 133926b..903000d 100644
47245--- a/drivers/scsi/scsi_transport_iscsi.c
47246+++ b/drivers/scsi/scsi_transport_iscsi.c
47247@@ -80,7 +80,7 @@ struct iscsi_internal {
47248 struct transport_container session_cont;
47249 };
47250
47251-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47252+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47253 static struct workqueue_struct *iscsi_eh_timer_workq;
47254
47255 static DEFINE_IDA(iscsi_sess_ida);
47256@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47257 int err;
47258
47259 ihost = shost->shost_data;
47260- session->sid = atomic_add_return(1, &iscsi_session_nr);
47261+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47262
47263 if (target_id == ISCSI_MAX_TARGET) {
47264 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47265@@ -3944,7 +3944,7 @@ static __init int iscsi_transport_init(void)
47266 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47267 ISCSI_TRANSPORT_VERSION);
47268
47269- atomic_set(&iscsi_session_nr, 0);
47270+ atomic_set_unchecked(&iscsi_session_nr, 0);
47271
47272 err = class_register(&iscsi_transport_class);
47273 if (err)
47274diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47275index f379c7f..e8fc69c 100644
47276--- a/drivers/scsi/scsi_transport_srp.c
47277+++ b/drivers/scsi/scsi_transport_srp.c
47278@@ -33,7 +33,7 @@
47279 #include "scsi_transport_srp_internal.h"
47280
47281 struct srp_host_attrs {
47282- atomic_t next_port_id;
47283+ atomic_unchecked_t next_port_id;
47284 };
47285 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47286
47287@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47288 struct Scsi_Host *shost = dev_to_shost(dev);
47289 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47290
47291- atomic_set(&srp_host->next_port_id, 0);
47292+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47293 return 0;
47294 }
47295
47296@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47297 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47298 rport->roles = ids->roles;
47299
47300- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47301+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47302 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47303
47304 transport_setup_device(&rport->dev);
47305diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47306index 610417e..167c46c 100644
47307--- a/drivers/scsi/sd.c
47308+++ b/drivers/scsi/sd.c
47309@@ -2928,7 +2928,7 @@ static int sd_probe(struct device *dev)
47310 sdkp->disk = gd;
47311 sdkp->index = index;
47312 atomic_set(&sdkp->openers, 0);
47313- atomic_set(&sdkp->device->ioerr_cnt, 0);
47314+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47315
47316 if (!sdp->request_queue->rq_timeout) {
47317 if (sdp->type != TYPE_MOD)
47318@@ -2941,7 +2941,7 @@ static int sd_probe(struct device *dev)
47319 device_initialize(&sdkp->dev);
47320 sdkp->dev.parent = dev;
47321 sdkp->dev.class = &sd_disk_class;
47322- dev_set_name(&sdkp->dev, dev_name(dev));
47323+ dev_set_name(&sdkp->dev, "%s", dev_name(dev));
47324
47325 if (device_add(&sdkp->dev))
47326 goto out_free_index;
47327diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47328index df5e961..df6b97f 100644
47329--- a/drivers/scsi/sg.c
47330+++ b/drivers/scsi/sg.c
47331@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47332 sdp->disk->disk_name,
47333 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47334 NULL,
47335- (char *)arg);
47336+ (char __user *)arg);
47337 case BLKTRACESTART:
47338 return blk_trace_startstop(sdp->device->request_queue, 1);
47339 case BLKTRACESTOP:
47340diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47341index 32b7bb1..2f1c4bd 100644
47342--- a/drivers/spi/spi.c
47343+++ b/drivers/spi/spi.c
47344@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47345 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47346
47347 /* portable code must never pass more than 32 bytes */
47348-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47349+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47350
47351 static u8 *buf;
47352
47353diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47354index ec9e2ae..cd15d67 100644
47355--- a/drivers/staging/android/timed_output.c
47356+++ b/drivers/staging/android/timed_output.c
47357@@ -25,7 +25,7 @@
47358 #include "timed_output.h"
47359
47360 static struct class *timed_output_class;
47361-static atomic_t device_count;
47362+static atomic_unchecked_t device_count;
47363
47364 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47365 char *buf)
47366@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47367 timed_output_class = class_create(THIS_MODULE, "timed_output");
47368 if (IS_ERR(timed_output_class))
47369 return PTR_ERR(timed_output_class);
47370- atomic_set(&device_count, 0);
47371+ atomic_set_unchecked(&device_count, 0);
47372 }
47373
47374 return 0;
47375@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47376 if (ret < 0)
47377 return ret;
47378
47379- tdev->index = atomic_inc_return(&device_count);
47380+ tdev->index = atomic_inc_return_unchecked(&device_count);
47381 tdev->dev = device_create(timed_output_class, NULL,
47382 MKDEV(0, tdev->index), NULL, tdev->name);
47383 if (IS_ERR(tdev->dev))
47384diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47385index 3675020..e80d92c 100644
47386--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47387+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47388@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47389
47390 static int solo_sysfs_init(struct solo_dev *solo_dev)
47391 {
47392- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47393+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47394 struct device *dev = &solo_dev->dev;
47395 const char *driver;
47396 int i;
47397diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47398index 3335941..2b26186 100644
47399--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47400+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47401@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47402
47403 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47404 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47405- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47406+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47407 if (p2m_id < 0)
47408 p2m_id = -p2m_id;
47409 }
47410diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47411index 6f91d2e..3f011d2 100644
47412--- a/drivers/staging/media/solo6x10/solo6x10.h
47413+++ b/drivers/staging/media/solo6x10/solo6x10.h
47414@@ -238,7 +238,7 @@ struct solo_dev {
47415
47416 /* P2M DMA Engine */
47417 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47418- atomic_t p2m_count;
47419+ atomic_unchecked_t p2m_count;
47420 int p2m_jiffies;
47421 unsigned int p2m_timeouts;
47422
47423diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47424index 34afc16..ffe44dd 100644
47425--- a/drivers/staging/octeon/ethernet-rx.c
47426+++ b/drivers/staging/octeon/ethernet-rx.c
47427@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47428 /* Increment RX stats for virtual ports */
47429 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47430 #ifdef CONFIG_64BIT
47431- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47432- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47433+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47434+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47435 #else
47436- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47437- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47438+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47439+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47440 #endif
47441 }
47442 netif_receive_skb(skb);
47443@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47444 dev->name);
47445 */
47446 #ifdef CONFIG_64BIT
47447- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47448+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47449 #else
47450- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47451+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47452 #endif
47453 dev_kfree_skb_irq(skb);
47454 }
47455diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47456index c3a90e7..023619a 100644
47457--- a/drivers/staging/octeon/ethernet.c
47458+++ b/drivers/staging/octeon/ethernet.c
47459@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47460 * since the RX tasklet also increments it.
47461 */
47462 #ifdef CONFIG_64BIT
47463- atomic64_add(rx_status.dropped_packets,
47464- (atomic64_t *)&priv->stats.rx_dropped);
47465+ atomic64_add_unchecked(rx_status.dropped_packets,
47466+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47467 #else
47468- atomic_add(rx_status.dropped_packets,
47469- (atomic_t *)&priv->stats.rx_dropped);
47470+ atomic_add_unchecked(rx_status.dropped_packets,
47471+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47472 #endif
47473 }
47474
47475diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47476index dc23395..cf7e9b1 100644
47477--- a/drivers/staging/rtl8712/rtl871x_io.h
47478+++ b/drivers/staging/rtl8712/rtl871x_io.h
47479@@ -108,7 +108,7 @@ struct _io_ops {
47480 u8 *pmem);
47481 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47482 u8 *pmem);
47483-};
47484+} __no_const;
47485
47486 struct io_req {
47487 struct list_head list;
47488diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47489index 1f5088b..0e59820 100644
47490--- a/drivers/staging/sbe-2t3e3/netdev.c
47491+++ b/drivers/staging/sbe-2t3e3/netdev.c
47492@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47493 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47494
47495 if (rlen)
47496- if (copy_to_user(data, &resp, rlen))
47497+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47498 return -EFAULT;
47499
47500 return 0;
47501diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47502index a863a98..d272795 100644
47503--- a/drivers/staging/usbip/vhci.h
47504+++ b/drivers/staging/usbip/vhci.h
47505@@ -83,7 +83,7 @@ struct vhci_hcd {
47506 unsigned resuming:1;
47507 unsigned long re_timeout;
47508
47509- atomic_t seqnum;
47510+ atomic_unchecked_t seqnum;
47511
47512 /*
47513 * NOTE:
47514diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47515index d7974cb..d78076b 100644
47516--- a/drivers/staging/usbip/vhci_hcd.c
47517+++ b/drivers/staging/usbip/vhci_hcd.c
47518@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47519
47520 spin_lock(&vdev->priv_lock);
47521
47522- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47523+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47524 if (priv->seqnum == 0xffff)
47525 dev_info(&urb->dev->dev, "seqnum max\n");
47526
47527@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47528 return -ENOMEM;
47529 }
47530
47531- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47532+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47533 if (unlink->seqnum == 0xffff)
47534 pr_info("seqnum max\n");
47535
47536@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47537 vdev->rhport = rhport;
47538 }
47539
47540- atomic_set(&vhci->seqnum, 0);
47541+ atomic_set_unchecked(&vhci->seqnum, 0);
47542 spin_lock_init(&vhci->lock);
47543
47544 hcd->power_budget = 0; /* no limit */
47545diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47546index d07fcb5..358e1e1 100644
47547--- a/drivers/staging/usbip/vhci_rx.c
47548+++ b/drivers/staging/usbip/vhci_rx.c
47549@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47550 if (!urb) {
47551 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47552 pr_info("max seqnum %d\n",
47553- atomic_read(&the_controller->seqnum));
47554+ atomic_read_unchecked(&the_controller->seqnum));
47555 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47556 return;
47557 }
47558diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47559index 8417c2f..ef5ebd6 100644
47560--- a/drivers/staging/vt6655/hostap.c
47561+++ b/drivers/staging/vt6655/hostap.c
47562@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47563 *
47564 */
47565
47566+static net_device_ops_no_const apdev_netdev_ops;
47567+
47568 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47569 {
47570 PSDevice apdev_priv;
47571 struct net_device *dev = pDevice->dev;
47572 int ret;
47573- const struct net_device_ops apdev_netdev_ops = {
47574- .ndo_start_xmit = pDevice->tx_80211,
47575- };
47576
47577 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47578
47579@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47580 *apdev_priv = *pDevice;
47581 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47582
47583+ /* only half broken now */
47584+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47585 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47586
47587 pDevice->apdev->type = ARPHRD_IEEE80211;
47588diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47589index c699a30..b90a5fd 100644
47590--- a/drivers/staging/vt6656/hostap.c
47591+++ b/drivers/staging/vt6656/hostap.c
47592@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47593 *
47594 */
47595
47596+static net_device_ops_no_const apdev_netdev_ops;
47597+
47598 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47599 {
47600 struct vnt_private *apdev_priv;
47601 struct net_device *dev = pDevice->dev;
47602 int ret;
47603- const struct net_device_ops apdev_netdev_ops = {
47604- .ndo_start_xmit = pDevice->tx_80211,
47605- };
47606
47607 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47608
47609@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47610 *apdev_priv = *pDevice;
47611 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47612
47613+ /* only half broken now */
47614+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47615 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47616
47617 pDevice->apdev->type = ARPHRD_IEEE80211;
47618diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47619index d128ce2..fc1f9a1 100644
47620--- a/drivers/staging/zcache/tmem.h
47621+++ b/drivers/staging/zcache/tmem.h
47622@@ -225,7 +225,7 @@ struct tmem_pamops {
47623 bool (*is_remote)(void *);
47624 int (*replace_in_obj)(void *, struct tmem_obj *);
47625 #endif
47626-};
47627+} __no_const;
47628 extern void tmem_register_pamops(struct tmem_pamops *m);
47629
47630 /* memory allocation methods provided by the host implementation */
47631@@ -234,7 +234,7 @@ struct tmem_hostops {
47632 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47633 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47634 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47635-};
47636+} __no_const;
47637 extern void tmem_register_hostops(struct tmem_hostops *m);
47638
47639 /* core tmem accessor functions */
47640diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47641index d3536f5..a0c2ce9 100644
47642--- a/drivers/target/sbp/sbp_target.c
47643+++ b/drivers/target/sbp/sbp_target.c
47644@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47645
47646 #define SESSION_MAINTENANCE_INTERVAL HZ
47647
47648-static atomic_t login_id = ATOMIC_INIT(0);
47649+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47650
47651 static void session_maintenance_work(struct work_struct *);
47652 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47653@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47654 login->lun = se_lun;
47655 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47656 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47657- login->login_id = atomic_inc_return(&login_id);
47658+ login->login_id = atomic_inc_return_unchecked(&login_id);
47659
47660 login->tgt_agt = sbp_target_agent_register(login);
47661 if (IS_ERR(login->tgt_agt)) {
47662diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47663index 4630481..c26782a 100644
47664--- a/drivers/target/target_core_device.c
47665+++ b/drivers/target/target_core_device.c
47666@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47667 spin_lock_init(&dev->se_port_lock);
47668 spin_lock_init(&dev->se_tmr_lock);
47669 spin_lock_init(&dev->qf_cmd_lock);
47670- atomic_set(&dev->dev_ordered_id, 0);
47671+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47672 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47673 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47674 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47675diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47676index 21e3158..43c6004 100644
47677--- a/drivers/target/target_core_transport.c
47678+++ b/drivers/target/target_core_transport.c
47679@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47680 * Used to determine when ORDERED commands should go from
47681 * Dormant to Active status.
47682 */
47683- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47684+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47685 smp_mb__after_atomic_inc();
47686 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47687 cmd->se_ordered_id, cmd->sam_task_attr,
47688diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47689index 33f83fe..d80f8e1 100644
47690--- a/drivers/tty/cyclades.c
47691+++ b/drivers/tty/cyclades.c
47692@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47693 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47694 info->port.count);
47695 #endif
47696- info->port.count++;
47697+ atomic_inc(&info->port.count);
47698 #ifdef CY_DEBUG_COUNT
47699 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47700- current->pid, info->port.count);
47701+ current->pid, atomic_read(&info->port.count));
47702 #endif
47703
47704 /*
47705@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47706 for (j = 0; j < cy_card[i].nports; j++) {
47707 info = &cy_card[i].ports[j];
47708
47709- if (info->port.count) {
47710+ if (atomic_read(&info->port.count)) {
47711 /* XXX is the ldisc num worth this? */
47712 struct tty_struct *tty;
47713 struct tty_ldisc *ld;
47714diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47715index eb255e8..f637a57 100644
47716--- a/drivers/tty/hvc/hvc_console.c
47717+++ b/drivers/tty/hvc/hvc_console.c
47718@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47719
47720 spin_lock_irqsave(&hp->port.lock, flags);
47721 /* Check and then increment for fast path open. */
47722- if (hp->port.count++ > 0) {
47723+ if (atomic_inc_return(&hp->port.count) > 1) {
47724 spin_unlock_irqrestore(&hp->port.lock, flags);
47725 hvc_kick();
47726 return 0;
47727@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47728
47729 spin_lock_irqsave(&hp->port.lock, flags);
47730
47731- if (--hp->port.count == 0) {
47732+ if (atomic_dec_return(&hp->port.count) == 0) {
47733 spin_unlock_irqrestore(&hp->port.lock, flags);
47734 /* We are done with the tty pointer now. */
47735 tty_port_tty_set(&hp->port, NULL);
47736@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47737 */
47738 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47739 } else {
47740- if (hp->port.count < 0)
47741+ if (atomic_read(&hp->port.count) < 0)
47742 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47743- hp->vtermno, hp->port.count);
47744+ hp->vtermno, atomic_read(&hp->port.count));
47745 spin_unlock_irqrestore(&hp->port.lock, flags);
47746 }
47747 }
47748@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47749 * open->hangup case this can be called after the final close so prevent
47750 * that from happening for now.
47751 */
47752- if (hp->port.count <= 0) {
47753+ if (atomic_read(&hp->port.count) <= 0) {
47754 spin_unlock_irqrestore(&hp->port.lock, flags);
47755 return;
47756 }
47757
47758- hp->port.count = 0;
47759+ atomic_set(&hp->port.count, 0);
47760 spin_unlock_irqrestore(&hp->port.lock, flags);
47761 tty_port_tty_set(&hp->port, NULL);
47762
47763@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47764 return -EPIPE;
47765
47766 /* FIXME what's this (unprotected) check for? */
47767- if (hp->port.count <= 0)
47768+ if (atomic_read(&hp->port.count) <= 0)
47769 return -EIO;
47770
47771 spin_lock_irqsave(&hp->lock, flags);
47772diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47773index 81e939e..95ead10 100644
47774--- a/drivers/tty/hvc/hvcs.c
47775+++ b/drivers/tty/hvc/hvcs.c
47776@@ -83,6 +83,7 @@
47777 #include <asm/hvcserver.h>
47778 #include <asm/uaccess.h>
47779 #include <asm/vio.h>
47780+#include <asm/local.h>
47781
47782 /*
47783 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47784@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47785
47786 spin_lock_irqsave(&hvcsd->lock, flags);
47787
47788- if (hvcsd->port.count > 0) {
47789+ if (atomic_read(&hvcsd->port.count) > 0) {
47790 spin_unlock_irqrestore(&hvcsd->lock, flags);
47791 printk(KERN_INFO "HVCS: vterm state unchanged. "
47792 "The hvcs device node is still in use.\n");
47793@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47794 }
47795 }
47796
47797- hvcsd->port.count = 0;
47798+ atomic_set(&hvcsd->port.count, 0);
47799 hvcsd->port.tty = tty;
47800 tty->driver_data = hvcsd;
47801
47802@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47803 unsigned long flags;
47804
47805 spin_lock_irqsave(&hvcsd->lock, flags);
47806- hvcsd->port.count++;
47807+ atomic_inc(&hvcsd->port.count);
47808 hvcsd->todo_mask |= HVCS_SCHED_READ;
47809 spin_unlock_irqrestore(&hvcsd->lock, flags);
47810
47811@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47812 hvcsd = tty->driver_data;
47813
47814 spin_lock_irqsave(&hvcsd->lock, flags);
47815- if (--hvcsd->port.count == 0) {
47816+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47817
47818 vio_disable_interrupts(hvcsd->vdev);
47819
47820@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47821
47822 free_irq(irq, hvcsd);
47823 return;
47824- } else if (hvcsd->port.count < 0) {
47825+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47826 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47827 " is missmanaged.\n",
47828- hvcsd->vdev->unit_address, hvcsd->port.count);
47829+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47830 }
47831
47832 spin_unlock_irqrestore(&hvcsd->lock, flags);
47833@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47834
47835 spin_lock_irqsave(&hvcsd->lock, flags);
47836 /* Preserve this so that we know how many kref refs to put */
47837- temp_open_count = hvcsd->port.count;
47838+ temp_open_count = atomic_read(&hvcsd->port.count);
47839
47840 /*
47841 * Don't kref put inside the spinlock because the destruction
47842@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47843 tty->driver_data = NULL;
47844 hvcsd->port.tty = NULL;
47845
47846- hvcsd->port.count = 0;
47847+ atomic_set(&hvcsd->port.count, 0);
47848
47849 /* This will drop any buffered data on the floor which is OK in a hangup
47850 * scenario. */
47851@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47852 * the middle of a write operation? This is a crummy place to do this
47853 * but we want to keep it all in the spinlock.
47854 */
47855- if (hvcsd->port.count <= 0) {
47856+ if (atomic_read(&hvcsd->port.count) <= 0) {
47857 spin_unlock_irqrestore(&hvcsd->lock, flags);
47858 return -ENODEV;
47859 }
47860@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47861 {
47862 struct hvcs_struct *hvcsd = tty->driver_data;
47863
47864- if (!hvcsd || hvcsd->port.count <= 0)
47865+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47866 return 0;
47867
47868 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47869diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47870index 4190199..48f2920 100644
47871--- a/drivers/tty/hvc/hvsi.c
47872+++ b/drivers/tty/hvc/hvsi.c
47873@@ -85,7 +85,7 @@ struct hvsi_struct {
47874 int n_outbuf;
47875 uint32_t vtermno;
47876 uint32_t virq;
47877- atomic_t seqno; /* HVSI packet sequence number */
47878+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47879 uint16_t mctrl;
47880 uint8_t state; /* HVSI protocol state */
47881 uint8_t flags;
47882@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47883
47884 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47885 packet.hdr.len = sizeof(struct hvsi_query_response);
47886- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47887+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47888 packet.verb = VSV_SEND_VERSION_NUMBER;
47889 packet.u.version = HVSI_VERSION;
47890 packet.query_seqno = query_seqno+1;
47891@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47892
47893 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47894 packet.hdr.len = sizeof(struct hvsi_query);
47895- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47896+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47897 packet.verb = verb;
47898
47899 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47900@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47901 int wrote;
47902
47903 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47904- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47905+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47906 packet.hdr.len = sizeof(struct hvsi_control);
47907 packet.verb = VSV_SET_MODEM_CTL;
47908 packet.mask = HVSI_TSDTR;
47909@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47910 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47911
47912 packet.hdr.type = VS_DATA_PACKET_HEADER;
47913- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47914+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47915 packet.hdr.len = count + sizeof(struct hvsi_header);
47916 memcpy(&packet.data, buf, count);
47917
47918@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47919 struct hvsi_control packet __ALIGNED__;
47920
47921 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47922- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47923+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47924 packet.hdr.len = 6;
47925 packet.verb = VSV_CLOSE_PROTOCOL;
47926
47927diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47928index 3396eb9..6d3d540 100644
47929--- a/drivers/tty/hvc/hvsi_lib.c
47930+++ b/drivers/tty/hvc/hvsi_lib.c
47931@@ -9,7 +9,7 @@
47932
47933 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47934 {
47935- packet->seqno = atomic_inc_return(&pv->seqno);
47936+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47937
47938 /* Assumes that always succeeds, works in practice */
47939 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47940@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47941
47942 /* Reset state */
47943 pv->established = 0;
47944- atomic_set(&pv->seqno, 0);
47945+ atomic_set_unchecked(&pv->seqno, 0);
47946
47947 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47948
47949@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47950 pv->mctrl_update = 0;
47951 q.hdr.type = VS_QUERY_PACKET_HEADER;
47952 q.hdr.len = sizeof(struct hvsi_query);
47953- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47954+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47955 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47956 rc = hvsi_send_packet(pv, &q.hdr);
47957 if (rc <= 0) {
47958diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47959index 8fd72ff..34a0bed 100644
47960--- a/drivers/tty/ipwireless/tty.c
47961+++ b/drivers/tty/ipwireless/tty.c
47962@@ -29,6 +29,7 @@
47963 #include <linux/tty_driver.h>
47964 #include <linux/tty_flip.h>
47965 #include <linux/uaccess.h>
47966+#include <asm/local.h>
47967
47968 #include "tty.h"
47969 #include "network.h"
47970@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47971 mutex_unlock(&tty->ipw_tty_mutex);
47972 return -ENODEV;
47973 }
47974- if (tty->port.count == 0)
47975+ if (atomic_read(&tty->port.count) == 0)
47976 tty->tx_bytes_queued = 0;
47977
47978- tty->port.count++;
47979+ atomic_inc(&tty->port.count);
47980
47981 tty->port.tty = linux_tty;
47982 linux_tty->driver_data = tty;
47983@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47984
47985 static void do_ipw_close(struct ipw_tty *tty)
47986 {
47987- tty->port.count--;
47988-
47989- if (tty->port.count == 0) {
47990+ if (atomic_dec_return(&tty->port.count) == 0) {
47991 struct tty_struct *linux_tty = tty->port.tty;
47992
47993 if (linux_tty != NULL) {
47994@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47995 return;
47996
47997 mutex_lock(&tty->ipw_tty_mutex);
47998- if (tty->port.count == 0) {
47999+ if (atomic_read(&tty->port.count) == 0) {
48000 mutex_unlock(&tty->ipw_tty_mutex);
48001 return;
48002 }
48003@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
48004
48005 mutex_lock(&tty->ipw_tty_mutex);
48006
48007- if (!tty->port.count) {
48008+ if (!atomic_read(&tty->port.count)) {
48009 mutex_unlock(&tty->ipw_tty_mutex);
48010 return;
48011 }
48012@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
48013 return -ENODEV;
48014
48015 mutex_lock(&tty->ipw_tty_mutex);
48016- if (!tty->port.count) {
48017+ if (!atomic_read(&tty->port.count)) {
48018 mutex_unlock(&tty->ipw_tty_mutex);
48019 return -EINVAL;
48020 }
48021@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
48022 if (!tty)
48023 return -ENODEV;
48024
48025- if (!tty->port.count)
48026+ if (!atomic_read(&tty->port.count))
48027 return -EINVAL;
48028
48029 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
48030@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
48031 if (!tty)
48032 return 0;
48033
48034- if (!tty->port.count)
48035+ if (!atomic_read(&tty->port.count))
48036 return 0;
48037
48038 return tty->tx_bytes_queued;
48039@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
48040 if (!tty)
48041 return -ENODEV;
48042
48043- if (!tty->port.count)
48044+ if (!atomic_read(&tty->port.count))
48045 return -EINVAL;
48046
48047 return get_control_lines(tty);
48048@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
48049 if (!tty)
48050 return -ENODEV;
48051
48052- if (!tty->port.count)
48053+ if (!atomic_read(&tty->port.count))
48054 return -EINVAL;
48055
48056 return set_control_lines(tty, set, clear);
48057@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
48058 if (!tty)
48059 return -ENODEV;
48060
48061- if (!tty->port.count)
48062+ if (!atomic_read(&tty->port.count))
48063 return -EINVAL;
48064
48065 /* FIXME: Exactly how is the tty object locked here .. */
48066@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
48067 * are gone */
48068 mutex_lock(&ttyj->ipw_tty_mutex);
48069 }
48070- while (ttyj->port.count)
48071+ while (atomic_read(&ttyj->port.count))
48072 do_ipw_close(ttyj);
48073 ipwireless_disassociate_network_ttys(network,
48074 ttyj->channel_idx);
48075diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48076index 1deaca4..c8582d4 100644
48077--- a/drivers/tty/moxa.c
48078+++ b/drivers/tty/moxa.c
48079@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48080 }
48081
48082 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48083- ch->port.count++;
48084+ atomic_inc(&ch->port.count);
48085 tty->driver_data = ch;
48086 tty_port_tty_set(&ch->port, tty);
48087 mutex_lock(&ch->port.mutex);
48088diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48089index 6422390..49003ac8 100644
48090--- a/drivers/tty/n_gsm.c
48091+++ b/drivers/tty/n_gsm.c
48092@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48093 spin_lock_init(&dlci->lock);
48094 mutex_init(&dlci->mutex);
48095 dlci->fifo = &dlci->_fifo;
48096- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48097+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48098 kfree(dlci);
48099 return NULL;
48100 }
48101@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48102 struct gsm_dlci *dlci = tty->driver_data;
48103 struct tty_port *port = &dlci->port;
48104
48105- port->count++;
48106+ atomic_inc(&port->count);
48107 dlci_get(dlci);
48108 dlci_get(dlci->gsm->dlci[0]);
48109 mux_get(dlci->gsm);
48110diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48111index 6c7fe90..9241dab 100644
48112--- a/drivers/tty/n_tty.c
48113+++ b/drivers/tty/n_tty.c
48114@@ -2203,6 +2203,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48115 {
48116 *ops = tty_ldisc_N_TTY;
48117 ops->owner = NULL;
48118- ops->refcount = ops->flags = 0;
48119+ atomic_set(&ops->refcount, 0);
48120+ ops->flags = 0;
48121 }
48122 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48123diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48124index abfd990..5ab5da9 100644
48125--- a/drivers/tty/pty.c
48126+++ b/drivers/tty/pty.c
48127@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
48128 panic("Couldn't register Unix98 pts driver");
48129
48130 /* Now create the /dev/ptmx special device */
48131+ pax_open_kernel();
48132 tty_default_fops(&ptmx_fops);
48133- ptmx_fops.open = ptmx_open;
48134+ *(void **)&ptmx_fops.open = ptmx_open;
48135+ pax_close_kernel();
48136
48137 cdev_init(&ptmx_cdev, &ptmx_fops);
48138 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48139diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48140index 354564e..fe50d9a 100644
48141--- a/drivers/tty/rocket.c
48142+++ b/drivers/tty/rocket.c
48143@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48144 tty->driver_data = info;
48145 tty_port_tty_set(port, tty);
48146
48147- if (port->count++ == 0) {
48148+ if (atomic_inc_return(&port->count) == 1) {
48149 atomic_inc(&rp_num_ports_open);
48150
48151 #ifdef ROCKET_DEBUG_OPEN
48152@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48153 #endif
48154 }
48155 #ifdef ROCKET_DEBUG_OPEN
48156- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48157+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48158 #endif
48159
48160 /*
48161@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48162 spin_unlock_irqrestore(&info->port.lock, flags);
48163 return;
48164 }
48165- if (info->port.count)
48166+ if (atomic_read(&info->port.count))
48167 atomic_dec(&rp_num_ports_open);
48168 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48169 spin_unlock_irqrestore(&info->port.lock, flags);
48170diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48171index e2520ab..034e20b 100644
48172--- a/drivers/tty/serial/ioc4_serial.c
48173+++ b/drivers/tty/serial/ioc4_serial.c
48174@@ -437,7 +437,7 @@ struct ioc4_soft {
48175 } is_intr_info[MAX_IOC4_INTR_ENTS];
48176
48177 /* Number of entries active in the above array */
48178- atomic_t is_num_intrs;
48179+ atomic_unchecked_t is_num_intrs;
48180 } is_intr_type[IOC4_NUM_INTR_TYPES];
48181
48182 /* is_ir_lock must be held while
48183@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48184 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48185 || (type == IOC4_OTHER_INTR_TYPE)));
48186
48187- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48188+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48189 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48190
48191 /* Save off the lower level interrupt handler */
48192@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48193
48194 soft = arg;
48195 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48196- num_intrs = (int)atomic_read(
48197+ num_intrs = (int)atomic_read_unchecked(
48198 &soft->is_intr_type[intr_type].is_num_intrs);
48199
48200 this_mir = this_ir = pending_intrs(soft, intr_type);
48201diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48202index 1002054..dd644a8 100644
48203--- a/drivers/tty/serial/kgdboc.c
48204+++ b/drivers/tty/serial/kgdboc.c
48205@@ -24,8 +24,9 @@
48206 #define MAX_CONFIG_LEN 40
48207
48208 static struct kgdb_io kgdboc_io_ops;
48209+static struct kgdb_io kgdboc_io_ops_console;
48210
48211-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48212+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48213 static int configured = -1;
48214
48215 static char config[MAX_CONFIG_LEN];
48216@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48217 kgdboc_unregister_kbd();
48218 if (configured == 1)
48219 kgdb_unregister_io_module(&kgdboc_io_ops);
48220+ else if (configured == 2)
48221+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48222 }
48223
48224 static int configure_kgdboc(void)
48225@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48226 int err;
48227 char *cptr = config;
48228 struct console *cons;
48229+ int is_console = 0;
48230
48231 err = kgdboc_option_setup(config);
48232 if (err || !strlen(config) || isspace(config[0]))
48233 goto noconfig;
48234
48235 err = -ENODEV;
48236- kgdboc_io_ops.is_console = 0;
48237 kgdb_tty_driver = NULL;
48238
48239 kgdboc_use_kms = 0;
48240@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48241 int idx;
48242 if (cons->device && cons->device(cons, &idx) == p &&
48243 idx == tty_line) {
48244- kgdboc_io_ops.is_console = 1;
48245+ is_console = 1;
48246 break;
48247 }
48248 cons = cons->next;
48249@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48250 kgdb_tty_line = tty_line;
48251
48252 do_register:
48253- err = kgdb_register_io_module(&kgdboc_io_ops);
48254+ if (is_console) {
48255+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48256+ configured = 2;
48257+ } else {
48258+ err = kgdb_register_io_module(&kgdboc_io_ops);
48259+ configured = 1;
48260+ }
48261 if (err)
48262 goto noconfig;
48263
48264@@ -205,8 +214,6 @@ do_register:
48265 if (err)
48266 goto nmi_con_failed;
48267
48268- configured = 1;
48269-
48270 return 0;
48271
48272 nmi_con_failed:
48273@@ -223,7 +230,7 @@ noconfig:
48274 static int __init init_kgdboc(void)
48275 {
48276 /* Already configured? */
48277- if (configured == 1)
48278+ if (configured >= 1)
48279 return 0;
48280
48281 return configure_kgdboc();
48282@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48283 if (config[len - 1] == '\n')
48284 config[len - 1] = '\0';
48285
48286- if (configured == 1)
48287+ if (configured >= 1)
48288 cleanup_kgdboc();
48289
48290 /* Go and configure with the new params. */
48291@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48292 .post_exception = kgdboc_post_exp_handler,
48293 };
48294
48295+static struct kgdb_io kgdboc_io_ops_console = {
48296+ .name = "kgdboc",
48297+ .read_char = kgdboc_get_char,
48298+ .write_char = kgdboc_put_char,
48299+ .pre_exception = kgdboc_pre_exp_handler,
48300+ .post_exception = kgdboc_post_exp_handler,
48301+ .is_console = 1
48302+};
48303+
48304 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48305 /* This is only available if kgdboc is a built in for early debugging */
48306 static int __init kgdboc_early_init(char *opt)
48307diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48308index b11e997..6d25a3b 100644
48309--- a/drivers/tty/serial/msm_serial.c
48310+++ b/drivers/tty/serial/msm_serial.c
48311@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48312 .cons = MSM_CONSOLE,
48313 };
48314
48315-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48316+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48317
48318 static int __init msm_serial_probe(struct platform_device *pdev)
48319 {
48320@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48321 int irq;
48322
48323 if (pdev->id == -1)
48324- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48325+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48326
48327 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48328 return -ENXIO;
48329diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48330index 0c8a9fa..234a95f 100644
48331--- a/drivers/tty/serial/samsung.c
48332+++ b/drivers/tty/serial/samsung.c
48333@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48334 }
48335 }
48336
48337+static int s3c64xx_serial_startup(struct uart_port *port);
48338 static int s3c24xx_serial_startup(struct uart_port *port)
48339 {
48340 struct s3c24xx_uart_port *ourport = to_ourport(port);
48341 int ret;
48342
48343+ /* Startup sequence is different for s3c64xx and higher SoC's */
48344+ if (s3c24xx_serial_has_interrupt_mask(port))
48345+ return s3c64xx_serial_startup(port);
48346+
48347 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48348 port->mapbase, port->membase);
48349
48350@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48351 /* setup info for port */
48352 port->dev = &platdev->dev;
48353
48354- /* Startup sequence is different for s3c64xx and higher SoC's */
48355- if (s3c24xx_serial_has_interrupt_mask(port))
48356- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48357-
48358 port->uartclk = 1;
48359
48360 if (cfg->uart_flags & UPF_CONS_FLOW) {
48361diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48362index f87dbfd..42ad4b1 100644
48363--- a/drivers/tty/serial/serial_core.c
48364+++ b/drivers/tty/serial/serial_core.c
48365@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
48366 uart_flush_buffer(tty);
48367 uart_shutdown(tty, state);
48368 spin_lock_irqsave(&port->lock, flags);
48369- port->count = 0;
48370+ atomic_set(&port->count, 0);
48371 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48372 spin_unlock_irqrestore(&port->lock, flags);
48373 tty_port_tty_set(port, NULL);
48374@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48375 goto end;
48376 }
48377
48378- port->count++;
48379+ atomic_inc(&port->count);
48380 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48381 retval = -ENXIO;
48382 goto err_dec_count;
48383@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48384 /*
48385 * Make sure the device is in D0 state.
48386 */
48387- if (port->count == 1)
48388+ if (atomic_read(&port->count) == 1)
48389 uart_change_pm(state, UART_PM_STATE_ON);
48390
48391 /*
48392@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48393 end:
48394 return retval;
48395 err_dec_count:
48396- port->count--;
48397+ atomic_inc(&port->count);
48398 mutex_unlock(&port->mutex);
48399 goto end;
48400 }
48401diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48402index 8eaf1ab..85c030d 100644
48403--- a/drivers/tty/synclink.c
48404+++ b/drivers/tty/synclink.c
48405@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48406
48407 if (debug_level >= DEBUG_LEVEL_INFO)
48408 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48409- __FILE__,__LINE__, info->device_name, info->port.count);
48410+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48411
48412 if (tty_port_close_start(&info->port, tty, filp) == 0)
48413 goto cleanup;
48414@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48415 cleanup:
48416 if (debug_level >= DEBUG_LEVEL_INFO)
48417 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48418- tty->driver->name, info->port.count);
48419+ tty->driver->name, atomic_read(&info->port.count));
48420
48421 } /* end of mgsl_close() */
48422
48423@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48424
48425 mgsl_flush_buffer(tty);
48426 shutdown(info);
48427-
48428- info->port.count = 0;
48429+
48430+ atomic_set(&info->port.count, 0);
48431 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48432 info->port.tty = NULL;
48433
48434@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48435
48436 if (debug_level >= DEBUG_LEVEL_INFO)
48437 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48438- __FILE__,__LINE__, tty->driver->name, port->count );
48439+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48440
48441 spin_lock_irqsave(&info->irq_spinlock, flags);
48442 if (!tty_hung_up_p(filp)) {
48443 extra_count = true;
48444- port->count--;
48445+ atomic_dec(&port->count);
48446 }
48447 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48448 port->blocked_open++;
48449@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48450
48451 if (debug_level >= DEBUG_LEVEL_INFO)
48452 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48453- __FILE__,__LINE__, tty->driver->name, port->count );
48454+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48455
48456 tty_unlock(tty);
48457 schedule();
48458@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48459
48460 /* FIXME: Racy on hangup during close wait */
48461 if (extra_count)
48462- port->count++;
48463+ atomic_inc(&port->count);
48464 port->blocked_open--;
48465
48466 if (debug_level >= DEBUG_LEVEL_INFO)
48467 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48468- __FILE__,__LINE__, tty->driver->name, port->count );
48469+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48470
48471 if (!retval)
48472 port->flags |= ASYNC_NORMAL_ACTIVE;
48473@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48474
48475 if (debug_level >= DEBUG_LEVEL_INFO)
48476 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48477- __FILE__,__LINE__,tty->driver->name, info->port.count);
48478+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48479
48480 /* If port is closing, signal caller to try again */
48481 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48482@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48483 spin_unlock_irqrestore(&info->netlock, flags);
48484 goto cleanup;
48485 }
48486- info->port.count++;
48487+ atomic_inc(&info->port.count);
48488 spin_unlock_irqrestore(&info->netlock, flags);
48489
48490- if (info->port.count == 1) {
48491+ if (atomic_read(&info->port.count) == 1) {
48492 /* 1st open on this device, init hardware */
48493 retval = startup(info);
48494 if (retval < 0)
48495@@ -3446,8 +3446,8 @@ cleanup:
48496 if (retval) {
48497 if (tty->count == 1)
48498 info->port.tty = NULL; /* tty layer will release tty struct */
48499- if(info->port.count)
48500- info->port.count--;
48501+ if (atomic_read(&info->port.count))
48502+ atomic_dec(&info->port.count);
48503 }
48504
48505 return retval;
48506@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48507 unsigned short new_crctype;
48508
48509 /* return error if TTY interface open */
48510- if (info->port.count)
48511+ if (atomic_read(&info->port.count))
48512 return -EBUSY;
48513
48514 switch (encoding)
48515@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48516
48517 /* arbitrate between network and tty opens */
48518 spin_lock_irqsave(&info->netlock, flags);
48519- if (info->port.count != 0 || info->netcount != 0) {
48520+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48521 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48522 spin_unlock_irqrestore(&info->netlock, flags);
48523 return -EBUSY;
48524@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48525 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48526
48527 /* return error if TTY interface open */
48528- if (info->port.count)
48529+ if (atomic_read(&info->port.count))
48530 return -EBUSY;
48531
48532 if (cmd != SIOCWANDEV)
48533diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48534index 1abf946..1ee34fc 100644
48535--- a/drivers/tty/synclink_gt.c
48536+++ b/drivers/tty/synclink_gt.c
48537@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48538 tty->driver_data = info;
48539 info->port.tty = tty;
48540
48541- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48542+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48543
48544 /* If port is closing, signal caller to try again */
48545 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48546@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48547 mutex_unlock(&info->port.mutex);
48548 goto cleanup;
48549 }
48550- info->port.count++;
48551+ atomic_inc(&info->port.count);
48552 spin_unlock_irqrestore(&info->netlock, flags);
48553
48554- if (info->port.count == 1) {
48555+ if (atomic_read(&info->port.count) == 1) {
48556 /* 1st open on this device, init hardware */
48557 retval = startup(info);
48558 if (retval < 0) {
48559@@ -715,8 +715,8 @@ cleanup:
48560 if (retval) {
48561 if (tty->count == 1)
48562 info->port.tty = NULL; /* tty layer will release tty struct */
48563- if(info->port.count)
48564- info->port.count--;
48565+ if(atomic_read(&info->port.count))
48566+ atomic_dec(&info->port.count);
48567 }
48568
48569 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48570@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48571
48572 if (sanity_check(info, tty->name, "close"))
48573 return;
48574- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48575+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48576
48577 if (tty_port_close_start(&info->port, tty, filp) == 0)
48578 goto cleanup;
48579@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48580 tty_port_close_end(&info->port, tty);
48581 info->port.tty = NULL;
48582 cleanup:
48583- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48584+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48585 }
48586
48587 static void hangup(struct tty_struct *tty)
48588@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48589 shutdown(info);
48590
48591 spin_lock_irqsave(&info->port.lock, flags);
48592- info->port.count = 0;
48593+ atomic_set(&info->port.count, 0);
48594 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48595 info->port.tty = NULL;
48596 spin_unlock_irqrestore(&info->port.lock, flags);
48597@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48598 unsigned short new_crctype;
48599
48600 /* return error if TTY interface open */
48601- if (info->port.count)
48602+ if (atomic_read(&info->port.count))
48603 return -EBUSY;
48604
48605 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48606@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48607
48608 /* arbitrate between network and tty opens */
48609 spin_lock_irqsave(&info->netlock, flags);
48610- if (info->port.count != 0 || info->netcount != 0) {
48611+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48612 DBGINFO(("%s hdlc_open busy\n", dev->name));
48613 spin_unlock_irqrestore(&info->netlock, flags);
48614 return -EBUSY;
48615@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48616 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48617
48618 /* return error if TTY interface open */
48619- if (info->port.count)
48620+ if (atomic_read(&info->port.count))
48621 return -EBUSY;
48622
48623 if (cmd != SIOCWANDEV)
48624@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48625 if (port == NULL)
48626 continue;
48627 spin_lock(&port->lock);
48628- if ((port->port.count || port->netcount) &&
48629+ if ((atomic_read(&port->port.count) || port->netcount) &&
48630 port->pending_bh && !port->bh_running &&
48631 !port->bh_requested) {
48632 DBGISR(("%s bh queued\n", port->device_name));
48633@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48634 spin_lock_irqsave(&info->lock, flags);
48635 if (!tty_hung_up_p(filp)) {
48636 extra_count = true;
48637- port->count--;
48638+ atomic_dec(&port->count);
48639 }
48640 spin_unlock_irqrestore(&info->lock, flags);
48641 port->blocked_open++;
48642@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48643 remove_wait_queue(&port->open_wait, &wait);
48644
48645 if (extra_count)
48646- port->count++;
48647+ atomic_inc(&port->count);
48648 port->blocked_open--;
48649
48650 if (!retval)
48651diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48652index ff17138..e38b41e 100644
48653--- a/drivers/tty/synclinkmp.c
48654+++ b/drivers/tty/synclinkmp.c
48655@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48656
48657 if (debug_level >= DEBUG_LEVEL_INFO)
48658 printk("%s(%d):%s open(), old ref count = %d\n",
48659- __FILE__,__LINE__,tty->driver->name, info->port.count);
48660+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48661
48662 /* If port is closing, signal caller to try again */
48663 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48664@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48665 spin_unlock_irqrestore(&info->netlock, flags);
48666 goto cleanup;
48667 }
48668- info->port.count++;
48669+ atomic_inc(&info->port.count);
48670 spin_unlock_irqrestore(&info->netlock, flags);
48671
48672- if (info->port.count == 1) {
48673+ if (atomic_read(&info->port.count) == 1) {
48674 /* 1st open on this device, init hardware */
48675 retval = startup(info);
48676 if (retval < 0)
48677@@ -796,8 +796,8 @@ cleanup:
48678 if (retval) {
48679 if (tty->count == 1)
48680 info->port.tty = NULL; /* tty layer will release tty struct */
48681- if(info->port.count)
48682- info->port.count--;
48683+ if(atomic_read(&info->port.count))
48684+ atomic_dec(&info->port.count);
48685 }
48686
48687 return retval;
48688@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48689
48690 if (debug_level >= DEBUG_LEVEL_INFO)
48691 printk("%s(%d):%s close() entry, count=%d\n",
48692- __FILE__,__LINE__, info->device_name, info->port.count);
48693+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48694
48695 if (tty_port_close_start(&info->port, tty, filp) == 0)
48696 goto cleanup;
48697@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48698 cleanup:
48699 if (debug_level >= DEBUG_LEVEL_INFO)
48700 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48701- tty->driver->name, info->port.count);
48702+ tty->driver->name, atomic_read(&info->port.count));
48703 }
48704
48705 /* Called by tty_hangup() when a hangup is signaled.
48706@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48707 shutdown(info);
48708
48709 spin_lock_irqsave(&info->port.lock, flags);
48710- info->port.count = 0;
48711+ atomic_set(&info->port.count, 0);
48712 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48713 info->port.tty = NULL;
48714 spin_unlock_irqrestore(&info->port.lock, flags);
48715@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48716 unsigned short new_crctype;
48717
48718 /* return error if TTY interface open */
48719- if (info->port.count)
48720+ if (atomic_read(&info->port.count))
48721 return -EBUSY;
48722
48723 switch (encoding)
48724@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48725
48726 /* arbitrate between network and tty opens */
48727 spin_lock_irqsave(&info->netlock, flags);
48728- if (info->port.count != 0 || info->netcount != 0) {
48729+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48730 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48731 spin_unlock_irqrestore(&info->netlock, flags);
48732 return -EBUSY;
48733@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48734 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48735
48736 /* return error if TTY interface open */
48737- if (info->port.count)
48738+ if (atomic_read(&info->port.count))
48739 return -EBUSY;
48740
48741 if (cmd != SIOCWANDEV)
48742@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48743 * do not request bottom half processing if the
48744 * device is not open in a normal mode.
48745 */
48746- if ( port && (port->port.count || port->netcount) &&
48747+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48748 port->pending_bh && !port->bh_running &&
48749 !port->bh_requested ) {
48750 if ( debug_level >= DEBUG_LEVEL_ISR )
48751@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48752
48753 if (debug_level >= DEBUG_LEVEL_INFO)
48754 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48755- __FILE__,__LINE__, tty->driver->name, port->count );
48756+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48757
48758 spin_lock_irqsave(&info->lock, flags);
48759 if (!tty_hung_up_p(filp)) {
48760 extra_count = true;
48761- port->count--;
48762+ atomic_dec(&port->count);
48763 }
48764 spin_unlock_irqrestore(&info->lock, flags);
48765 port->blocked_open++;
48766@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48767
48768 if (debug_level >= DEBUG_LEVEL_INFO)
48769 printk("%s(%d):%s block_til_ready() count=%d\n",
48770- __FILE__,__LINE__, tty->driver->name, port->count );
48771+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48772
48773 tty_unlock(tty);
48774 schedule();
48775@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48776 remove_wait_queue(&port->open_wait, &wait);
48777
48778 if (extra_count)
48779- port->count++;
48780+ atomic_inc(&port->count);
48781 port->blocked_open--;
48782
48783 if (debug_level >= DEBUG_LEVEL_INFO)
48784 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48785- __FILE__,__LINE__, tty->driver->name, port->count );
48786+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48787
48788 if (!retval)
48789 port->flags |= ASYNC_NORMAL_ACTIVE;
48790diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48791index b51c154..17d55d1 100644
48792--- a/drivers/tty/sysrq.c
48793+++ b/drivers/tty/sysrq.c
48794@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48795 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48796 size_t count, loff_t *ppos)
48797 {
48798- if (count) {
48799+ if (count && capable(CAP_SYS_ADMIN)) {
48800 char c;
48801
48802 if (get_user(c, buf))
48803diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48804index 4476682..d77e748 100644
48805--- a/drivers/tty/tty_io.c
48806+++ b/drivers/tty/tty_io.c
48807@@ -3466,7 +3466,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48808
48809 void tty_default_fops(struct file_operations *fops)
48810 {
48811- *fops = tty_fops;
48812+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48813 }
48814
48815 /*
48816diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48817index 1afe192..73d2c20 100644
48818--- a/drivers/tty/tty_ldisc.c
48819+++ b/drivers/tty/tty_ldisc.c
48820@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48821 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48822 tty_ldiscs[disc] = new_ldisc;
48823 new_ldisc->num = disc;
48824- new_ldisc->refcount = 0;
48825+ atomic_set(&new_ldisc->refcount, 0);
48826 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48827
48828 return ret;
48829@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48830 return -EINVAL;
48831
48832 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48833- if (tty_ldiscs[disc]->refcount)
48834+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48835 ret = -EBUSY;
48836 else
48837 tty_ldiscs[disc] = NULL;
48838@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48839 if (ldops) {
48840 ret = ERR_PTR(-EAGAIN);
48841 if (try_module_get(ldops->owner)) {
48842- ldops->refcount++;
48843+ atomic_inc(&ldops->refcount);
48844 ret = ldops;
48845 }
48846 }
48847@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48848 unsigned long flags;
48849
48850 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48851- ldops->refcount--;
48852+ atomic_dec(&ldops->refcount);
48853 module_put(ldops->owner);
48854 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48855 }
48856@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48857 /* unreleased reader reference(s) will cause this WARN */
48858 WARN_ON(!atomic_dec_and_test(&ld->users));
48859
48860- ld->ops->refcount--;
48861+ atomic_dec(&ld->ops->refcount);
48862 module_put(ld->ops->owner);
48863 kfree(ld);
48864 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48865diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48866index f597e88..b7f68ed 100644
48867--- a/drivers/tty/tty_port.c
48868+++ b/drivers/tty/tty_port.c
48869@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48870 unsigned long flags;
48871
48872 spin_lock_irqsave(&port->lock, flags);
48873- port->count = 0;
48874+ atomic_set(&port->count, 0);
48875 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48876 tty = port->tty;
48877 if (tty)
48878@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48879 /* The port lock protects the port counts */
48880 spin_lock_irqsave(&port->lock, flags);
48881 if (!tty_hung_up_p(filp))
48882- port->count--;
48883+ atomic_dec(&port->count);
48884 port->blocked_open++;
48885 spin_unlock_irqrestore(&port->lock, flags);
48886
48887@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48888 we must not mess that up further */
48889 spin_lock_irqsave(&port->lock, flags);
48890 if (!tty_hung_up_p(filp))
48891- port->count++;
48892+ atomic_inc(&port->count);
48893 port->blocked_open--;
48894 if (retval == 0)
48895 port->flags |= ASYNC_NORMAL_ACTIVE;
48896@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48897 return 0;
48898 }
48899
48900- if (tty->count == 1 && port->count != 1) {
48901+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48902 printk(KERN_WARNING
48903 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48904- port->count);
48905- port->count = 1;
48906+ atomic_read(&port->count));
48907+ atomic_set(&port->count, 1);
48908 }
48909- if (--port->count < 0) {
48910+ if (atomic_dec_return(&port->count) < 0) {
48911 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48912- port->count);
48913- port->count = 0;
48914+ atomic_read(&port->count));
48915+ atomic_set(&port->count, 0);
48916 }
48917
48918- if (port->count) {
48919+ if (atomic_read(&port->count)) {
48920 spin_unlock_irqrestore(&port->lock, flags);
48921 if (port->ops->drop)
48922 port->ops->drop(port);
48923@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48924 {
48925 spin_lock_irq(&port->lock);
48926 if (!tty_hung_up_p(filp))
48927- ++port->count;
48928+ atomic_inc(&port->count);
48929 spin_unlock_irq(&port->lock);
48930 tty_port_tty_set(port, tty);
48931
48932diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48933index a9af1b9a..1e08e7f 100644
48934--- a/drivers/tty/vt/keyboard.c
48935+++ b/drivers/tty/vt/keyboard.c
48936@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48937 kbd->kbdmode == VC_OFF) &&
48938 value != KVAL(K_SAK))
48939 return; /* SAK is allowed even in raw mode */
48940+
48941+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48942+ {
48943+ void *func = fn_handler[value];
48944+ if (func == fn_show_state || func == fn_show_ptregs ||
48945+ func == fn_show_mem)
48946+ return;
48947+ }
48948+#endif
48949+
48950 fn_handler[value](vc);
48951 }
48952
48953@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48954 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48955 return -EFAULT;
48956
48957- if (!capable(CAP_SYS_TTY_CONFIG))
48958- perm = 0;
48959-
48960 switch (cmd) {
48961 case KDGKBENT:
48962 /* Ensure another thread doesn't free it under us */
48963@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48964 spin_unlock_irqrestore(&kbd_event_lock, flags);
48965 return put_user(val, &user_kbe->kb_value);
48966 case KDSKBENT:
48967+ if (!capable(CAP_SYS_TTY_CONFIG))
48968+ perm = 0;
48969+
48970 if (!perm)
48971 return -EPERM;
48972 if (!i && v == K_NOSUCHMAP) {
48973@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48974 int i, j, k;
48975 int ret;
48976
48977- if (!capable(CAP_SYS_TTY_CONFIG))
48978- perm = 0;
48979-
48980 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48981 if (!kbs) {
48982 ret = -ENOMEM;
48983@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48984 kfree(kbs);
48985 return ((p && *p) ? -EOVERFLOW : 0);
48986 case KDSKBSENT:
48987+ if (!capable(CAP_SYS_TTY_CONFIG))
48988+ perm = 0;
48989+
48990 if (!perm) {
48991 ret = -EPERM;
48992 goto reterr;
48993diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48994index b645c47..a55c182 100644
48995--- a/drivers/uio/uio.c
48996+++ b/drivers/uio/uio.c
48997@@ -25,6 +25,7 @@
48998 #include <linux/kobject.h>
48999 #include <linux/cdev.h>
49000 #include <linux/uio_driver.h>
49001+#include <asm/local.h>
49002
49003 #define UIO_MAX_DEVICES (1U << MINORBITS)
49004
49005@@ -32,10 +33,10 @@ struct uio_device {
49006 struct module *owner;
49007 struct device *dev;
49008 int minor;
49009- atomic_t event;
49010+ atomic_unchecked_t event;
49011 struct fasync_struct *async_queue;
49012 wait_queue_head_t wait;
49013- int vma_count;
49014+ local_t vma_count;
49015 struct uio_info *info;
49016 struct kobject *map_dir;
49017 struct kobject *portio_dir;
49018@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
49019 struct device_attribute *attr, char *buf)
49020 {
49021 struct uio_device *idev = dev_get_drvdata(dev);
49022- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
49023+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
49024 }
49025
49026 static struct device_attribute uio_class_attributes[] = {
49027@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
49028 {
49029 struct uio_device *idev = info->uio_dev;
49030
49031- atomic_inc(&idev->event);
49032+ atomic_inc_unchecked(&idev->event);
49033 wake_up_interruptible(&idev->wait);
49034 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
49035 }
49036@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
49037 }
49038
49039 listener->dev = idev;
49040- listener->event_count = atomic_read(&idev->event);
49041+ listener->event_count = atomic_read_unchecked(&idev->event);
49042 filep->private_data = listener;
49043
49044 if (idev->info->open) {
49045@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
49046 return -EIO;
49047
49048 poll_wait(filep, &idev->wait, wait);
49049- if (listener->event_count != atomic_read(&idev->event))
49050+ if (listener->event_count != atomic_read_unchecked(&idev->event))
49051 return POLLIN | POLLRDNORM;
49052 return 0;
49053 }
49054@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
49055 do {
49056 set_current_state(TASK_INTERRUPTIBLE);
49057
49058- event_count = atomic_read(&idev->event);
49059+ event_count = atomic_read_unchecked(&idev->event);
49060 if (event_count != listener->event_count) {
49061 if (copy_to_user(buf, &event_count, count))
49062 retval = -EFAULT;
49063@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
49064 static void uio_vma_open(struct vm_area_struct *vma)
49065 {
49066 struct uio_device *idev = vma->vm_private_data;
49067- idev->vma_count++;
49068+ local_inc(&idev->vma_count);
49069 }
49070
49071 static void uio_vma_close(struct vm_area_struct *vma)
49072 {
49073 struct uio_device *idev = vma->vm_private_data;
49074- idev->vma_count--;
49075+ local_dec(&idev->vma_count);
49076 }
49077
49078 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
49079@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
49080 idev->owner = owner;
49081 idev->info = info;
49082 init_waitqueue_head(&idev->wait);
49083- atomic_set(&idev->event, 0);
49084+ atomic_set_unchecked(&idev->event, 0);
49085
49086 ret = uio_get_minor(idev);
49087 if (ret)
49088diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49089index 8a7eb77..c00402f 100644
49090--- a/drivers/usb/atm/cxacru.c
49091+++ b/drivers/usb/atm/cxacru.c
49092@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49093 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49094 if (ret < 2)
49095 return -EINVAL;
49096- if (index < 0 || index > 0x7f)
49097+ if (index > 0x7f)
49098 return -EINVAL;
49099 pos += tmp;
49100
49101diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49102index d3527dd..26effa2 100644
49103--- a/drivers/usb/atm/usbatm.c
49104+++ b/drivers/usb/atm/usbatm.c
49105@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49106 if (printk_ratelimit())
49107 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49108 __func__, vpi, vci);
49109- atomic_inc(&vcc->stats->rx_err);
49110+ atomic_inc_unchecked(&vcc->stats->rx_err);
49111 return;
49112 }
49113
49114@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49115 if (length > ATM_MAX_AAL5_PDU) {
49116 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49117 __func__, length, vcc);
49118- atomic_inc(&vcc->stats->rx_err);
49119+ atomic_inc_unchecked(&vcc->stats->rx_err);
49120 goto out;
49121 }
49122
49123@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49124 if (sarb->len < pdu_length) {
49125 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49126 __func__, pdu_length, sarb->len, vcc);
49127- atomic_inc(&vcc->stats->rx_err);
49128+ atomic_inc_unchecked(&vcc->stats->rx_err);
49129 goto out;
49130 }
49131
49132 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49133 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49134 __func__, vcc);
49135- atomic_inc(&vcc->stats->rx_err);
49136+ atomic_inc_unchecked(&vcc->stats->rx_err);
49137 goto out;
49138 }
49139
49140@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49141 if (printk_ratelimit())
49142 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49143 __func__, length);
49144- atomic_inc(&vcc->stats->rx_drop);
49145+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49146 goto out;
49147 }
49148
49149@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49150
49151 vcc->push(vcc, skb);
49152
49153- atomic_inc(&vcc->stats->rx);
49154+ atomic_inc_unchecked(&vcc->stats->rx);
49155 out:
49156 skb_trim(sarb, 0);
49157 }
49158@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
49159 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49160
49161 usbatm_pop(vcc, skb);
49162- atomic_inc(&vcc->stats->tx);
49163+ atomic_inc_unchecked(&vcc->stats->tx);
49164
49165 skb = skb_dequeue(&instance->sndqueue);
49166 }
49167@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49168 if (!left--)
49169 return sprintf(page,
49170 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49171- atomic_read(&atm_dev->stats.aal5.tx),
49172- atomic_read(&atm_dev->stats.aal5.tx_err),
49173- atomic_read(&atm_dev->stats.aal5.rx),
49174- atomic_read(&atm_dev->stats.aal5.rx_err),
49175- atomic_read(&atm_dev->stats.aal5.rx_drop));
49176+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49177+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49178+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49179+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49180+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49181
49182 if (!left--) {
49183 if (instance->disconnected)
49184diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49185index 2a3bbdf..91d72cf 100644
49186--- a/drivers/usb/core/devices.c
49187+++ b/drivers/usb/core/devices.c
49188@@ -126,7 +126,7 @@ static const char format_endpt[] =
49189 * time it gets called.
49190 */
49191 static struct device_connect_event {
49192- atomic_t count;
49193+ atomic_unchecked_t count;
49194 wait_queue_head_t wait;
49195 } device_event = {
49196 .count = ATOMIC_INIT(1),
49197@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49198
49199 void usbfs_conn_disc_event(void)
49200 {
49201- atomic_add(2, &device_event.count);
49202+ atomic_add_unchecked(2, &device_event.count);
49203 wake_up(&device_event.wait);
49204 }
49205
49206@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49207
49208 poll_wait(file, &device_event.wait, wait);
49209
49210- event_count = atomic_read(&device_event.count);
49211+ event_count = atomic_read_unchecked(&device_event.count);
49212 if (file->f_version != event_count) {
49213 file->f_version = event_count;
49214 return POLLIN | POLLRDNORM;
49215diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49216index d53547d..6a22d02 100644
49217--- a/drivers/usb/core/hcd.c
49218+++ b/drivers/usb/core/hcd.c
49219@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49220 */
49221 usb_get_urb(urb);
49222 atomic_inc(&urb->use_count);
49223- atomic_inc(&urb->dev->urbnum);
49224+ atomic_inc_unchecked(&urb->dev->urbnum);
49225 usbmon_urb_submit(&hcd->self, urb);
49226
49227 /* NOTE requirements on root-hub callers (usbfs and the hub
49228@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49229 urb->hcpriv = NULL;
49230 INIT_LIST_HEAD(&urb->urb_list);
49231 atomic_dec(&urb->use_count);
49232- atomic_dec(&urb->dev->urbnum);
49233+ atomic_dec_unchecked(&urb->dev->urbnum);
49234 if (atomic_read(&urb->reject))
49235 wake_up(&usb_kill_urb_queue);
49236 usb_put_urb(urb);
49237diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49238index da2905a..834a569 100644
49239--- a/drivers/usb/core/hub.c
49240+++ b/drivers/usb/core/hub.c
49241@@ -27,6 +27,7 @@
49242 #include <linux/freezer.h>
49243 #include <linux/random.h>
49244 #include <linux/pm_qos.h>
49245+#include <linux/grsecurity.h>
49246
49247 #include <asm/uaccess.h>
49248 #include <asm/byteorder.h>
49249@@ -4424,6 +4425,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49250 goto done;
49251 return;
49252 }
49253+
49254+ if (gr_handle_new_usb())
49255+ goto done;
49256+
49257 if (hub_is_superspeed(hub->hdev))
49258 unit_load = 150;
49259 else
49260diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49261index 444d30e..f15c850 100644
49262--- a/drivers/usb/core/message.c
49263+++ b/drivers/usb/core/message.c
49264@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49265 * method can wait for it to complete. Since you don't have a handle on the
49266 * URB used, you can't cancel the request.
49267 */
49268-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49269+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49270 __u8 requesttype, __u16 value, __u16 index, void *data,
49271 __u16 size, int timeout)
49272 {
49273diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49274index aa38db4..0a08682 100644
49275--- a/drivers/usb/core/sysfs.c
49276+++ b/drivers/usb/core/sysfs.c
49277@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49278 struct usb_device *udev;
49279
49280 udev = to_usb_device(dev);
49281- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49282+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49283 }
49284 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49285
49286diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49287index b10da72..43aa0b2 100644
49288--- a/drivers/usb/core/usb.c
49289+++ b/drivers/usb/core/usb.c
49290@@ -389,7 +389,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49291 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49292 dev->state = USB_STATE_ATTACHED;
49293 dev->lpm_disable_count = 1;
49294- atomic_set(&dev->urbnum, 0);
49295+ atomic_set_unchecked(&dev->urbnum, 0);
49296
49297 INIT_LIST_HEAD(&dev->ep0.urb_list);
49298 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49299diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49300index f77083f..f3e2e34 100644
49301--- a/drivers/usb/dwc3/gadget.c
49302+++ b/drivers/usb/dwc3/gadget.c
49303@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49304 if (!usb_endpoint_xfer_isoc(desc))
49305 return 0;
49306
49307- memset(&trb_link, 0, sizeof(trb_link));
49308-
49309 /* Link TRB for ISOC. The HWO bit is never reset */
49310 trb_st_hw = &dep->trb_pool[0];
49311
49312diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49313index 5e29dde..eca992f 100644
49314--- a/drivers/usb/early/ehci-dbgp.c
49315+++ b/drivers/usb/early/ehci-dbgp.c
49316@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49317
49318 #ifdef CONFIG_KGDB
49319 static struct kgdb_io kgdbdbgp_io_ops;
49320-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49321+static struct kgdb_io kgdbdbgp_io_ops_console;
49322+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49323 #else
49324 #define dbgp_kgdb_mode (0)
49325 #endif
49326@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49327 .write_char = kgdbdbgp_write_char,
49328 };
49329
49330+static struct kgdb_io kgdbdbgp_io_ops_console = {
49331+ .name = "kgdbdbgp",
49332+ .read_char = kgdbdbgp_read_char,
49333+ .write_char = kgdbdbgp_write_char,
49334+ .is_console = 1
49335+};
49336+
49337 static int kgdbdbgp_wait_time;
49338
49339 static int __init kgdbdbgp_parse_config(char *str)
49340@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49341 ptr++;
49342 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49343 }
49344- kgdb_register_io_module(&kgdbdbgp_io_ops);
49345- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49346+ if (early_dbgp_console.index != -1)
49347+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49348+ else
49349+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49350
49351 return 0;
49352 }
49353diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49354index b369292..9f3ba40 100644
49355--- a/drivers/usb/gadget/u_serial.c
49356+++ b/drivers/usb/gadget/u_serial.c
49357@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49358 spin_lock_irq(&port->port_lock);
49359
49360 /* already open? Great. */
49361- if (port->port.count) {
49362+ if (atomic_read(&port->port.count)) {
49363 status = 0;
49364- port->port.count++;
49365+ atomic_inc(&port->port.count);
49366
49367 /* currently opening/closing? wait ... */
49368 } else if (port->openclose) {
49369@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49370 tty->driver_data = port;
49371 port->port.tty = tty;
49372
49373- port->port.count = 1;
49374+ atomic_set(&port->port.count, 1);
49375 port->openclose = false;
49376
49377 /* if connected, start the I/O stream */
49378@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49379
49380 spin_lock_irq(&port->port_lock);
49381
49382- if (port->port.count != 1) {
49383- if (port->port.count == 0)
49384+ if (atomic_read(&port->port.count) != 1) {
49385+ if (atomic_read(&port->port.count) == 0)
49386 WARN_ON(1);
49387 else
49388- --port->port.count;
49389+ atomic_dec(&port->port.count);
49390 goto exit;
49391 }
49392
49393@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49394 * and sleep if necessary
49395 */
49396 port->openclose = true;
49397- port->port.count = 0;
49398+ atomic_set(&port->port.count, 0);
49399
49400 gser = port->port_usb;
49401 if (gser && gser->disconnect)
49402@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49403 int cond;
49404
49405 spin_lock_irq(&port->port_lock);
49406- cond = (port->port.count == 0) && !port->openclose;
49407+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49408 spin_unlock_irq(&port->port_lock);
49409 return cond;
49410 }
49411@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49412 /* if it's already open, start I/O ... and notify the serial
49413 * protocol about open/close status (connect/disconnect).
49414 */
49415- if (port->port.count) {
49416+ if (atomic_read(&port->port.count)) {
49417 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49418 gs_start_io(port);
49419 if (gser->connect)
49420@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49421
49422 port->port_usb = NULL;
49423 gser->ioport = NULL;
49424- if (port->port.count > 0 || port->openclose) {
49425+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49426 wake_up_interruptible(&port->drain_wait);
49427 if (port->port.tty)
49428 tty_hangup(port->port.tty);
49429@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49430
49431 /* finally, free any unused/unusable I/O buffers */
49432 spin_lock_irqsave(&port->port_lock, flags);
49433- if (port->port.count == 0 && !port->openclose)
49434+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49435 gs_buf_free(&port->port_write_buf);
49436 gs_free_requests(gser->out, &port->read_pool, NULL);
49437 gs_free_requests(gser->out, &port->read_queue, NULL);
49438diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49439index ba6a5d6..f88f7f3 100644
49440--- a/drivers/usb/misc/appledisplay.c
49441+++ b/drivers/usb/misc/appledisplay.c
49442@@ -83,7 +83,7 @@ struct appledisplay {
49443 spinlock_t lock;
49444 };
49445
49446-static atomic_t count_displays = ATOMIC_INIT(0);
49447+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49448 static struct workqueue_struct *wq;
49449
49450 static void appledisplay_complete(struct urb *urb)
49451@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49452
49453 /* Register backlight device */
49454 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49455- atomic_inc_return(&count_displays) - 1);
49456+ atomic_inc_return_unchecked(&count_displays) - 1);
49457 memset(&props, 0, sizeof(struct backlight_properties));
49458 props.type = BACKLIGHT_RAW;
49459 props.max_brightness = 0xff;
49460diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49461index 5f3bcd3..bfca43f 100644
49462--- a/drivers/usb/serial/console.c
49463+++ b/drivers/usb/serial/console.c
49464@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49465
49466 info->port = port;
49467
49468- ++port->port.count;
49469+ atomic_inc(&port->port.count);
49470 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49471 if (serial->type->set_termios) {
49472 /*
49473@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49474 }
49475 /* Now that any required fake tty operations are completed restore
49476 * the tty port count */
49477- --port->port.count;
49478+ atomic_dec(&port->port.count);
49479 /* The console is special in terms of closing the device so
49480 * indicate this port is now acting as a system console. */
49481 port->port.console = 1;
49482@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49483 free_tty:
49484 kfree(tty);
49485 reset_open_count:
49486- port->port.count = 0;
49487+ atomic_set(&port->port.count, 0);
49488 usb_autopm_put_interface(serial->interface);
49489 error_get_interface:
49490 usb_serial_put(serial);
49491diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49492index 75f70f0..d467e1a 100644
49493--- a/drivers/usb/storage/usb.h
49494+++ b/drivers/usb/storage/usb.h
49495@@ -63,7 +63,7 @@ struct us_unusual_dev {
49496 __u8 useProtocol;
49497 __u8 useTransport;
49498 int (*initFunction)(struct us_data *);
49499-};
49500+} __do_const;
49501
49502
49503 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49504diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49505index d6bea3e..60b250e 100644
49506--- a/drivers/usb/wusbcore/wa-hc.h
49507+++ b/drivers/usb/wusbcore/wa-hc.h
49508@@ -192,7 +192,7 @@ struct wahc {
49509 struct list_head xfer_delayed_list;
49510 spinlock_t xfer_list_lock;
49511 struct work_struct xfer_work;
49512- atomic_t xfer_id_count;
49513+ atomic_unchecked_t xfer_id_count;
49514 };
49515
49516
49517@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49518 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49519 spin_lock_init(&wa->xfer_list_lock);
49520 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49521- atomic_set(&wa->xfer_id_count, 1);
49522+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49523 }
49524
49525 /**
49526diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49527index 028fc83..65bb105 100644
49528--- a/drivers/usb/wusbcore/wa-xfer.c
49529+++ b/drivers/usb/wusbcore/wa-xfer.c
49530@@ -296,7 +296,7 @@ out:
49531 */
49532 static void wa_xfer_id_init(struct wa_xfer *xfer)
49533 {
49534- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49535+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49536 }
49537
49538 /*
49539diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49540index 6d78736..65be90e 100644
49541--- a/drivers/vfio/vfio.c
49542+++ b/drivers/vfio/vfio.c
49543@@ -486,7 +486,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49544 return 0;
49545
49546 /* TODO Prevent device auto probing */
49547- WARN("Device %s added to live group %d!\n", dev_name(dev),
49548+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49549 iommu_group_id(group->iommu_group));
49550
49551 return 0;
49552@@ -506,7 +506,7 @@ static int vfio_group_nb_del_dev(struct vfio_group *group, struct device *dev)
49553 if (likely(!device))
49554 return 0;
49555
49556- WARN("Device %s removed from live group %d!\n", dev_name(dev),
49557+ WARN(1, "Device %s removed from live group %d!\n", dev_name(dev),
49558 iommu_group_id(group->iommu_group));
49559
49560 vfio_device_put(device);
49561diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49562index 5174eba..86e764a 100644
49563--- a/drivers/vhost/vringh.c
49564+++ b/drivers/vhost/vringh.c
49565@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49566
49567 static inline int putu16_kern(u16 *p, u16 val)
49568 {
49569- ACCESS_ONCE(*p) = val;
49570+ ACCESS_ONCE_RW(*p) = val;
49571 return 0;
49572 }
49573
49574diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49575index 8c55011..eed4ae1a 100644
49576--- a/drivers/video/aty/aty128fb.c
49577+++ b/drivers/video/aty/aty128fb.c
49578@@ -149,7 +149,7 @@ enum {
49579 };
49580
49581 /* Must match above enum */
49582-static char * const r128_family[] = {
49583+static const char * const r128_family[] = {
49584 "AGP",
49585 "PCI",
49586 "PRO AGP",
49587diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49588index 4f27fdc..d3537e6 100644
49589--- a/drivers/video/aty/atyfb_base.c
49590+++ b/drivers/video/aty/atyfb_base.c
49591@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
49592 par->accel_flags = var->accel_flags; /* hack */
49593
49594 if (var->accel_flags) {
49595- info->fbops->fb_sync = atyfb_sync;
49596+ pax_open_kernel();
49597+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49598+ pax_close_kernel();
49599 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49600 } else {
49601- info->fbops->fb_sync = NULL;
49602+ pax_open_kernel();
49603+ *(void **)&info->fbops->fb_sync = NULL;
49604+ pax_close_kernel();
49605 info->flags |= FBINFO_HWACCEL_DISABLED;
49606 }
49607
49608diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49609index 95ec042..e6affdd 100644
49610--- a/drivers/video/aty/mach64_cursor.c
49611+++ b/drivers/video/aty/mach64_cursor.c
49612@@ -7,6 +7,7 @@
49613 #include <linux/string.h>
49614
49615 #include <asm/io.h>
49616+#include <asm/pgtable.h>
49617
49618 #ifdef __sparc__
49619 #include <asm/fbio.h>
49620@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49621 info->sprite.buf_align = 16; /* and 64 lines tall. */
49622 info->sprite.flags = FB_PIXMAP_IO;
49623
49624- info->fbops->fb_cursor = atyfb_cursor;
49625+ pax_open_kernel();
49626+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49627+ pax_close_kernel();
49628
49629 return 0;
49630 }
49631diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
49632index c74e7aa..e3c2790 100644
49633--- a/drivers/video/backlight/backlight.c
49634+++ b/drivers/video/backlight/backlight.c
49635@@ -304,7 +304,7 @@ struct backlight_device *backlight_device_register(const char *name,
49636 new_bd->dev.class = backlight_class;
49637 new_bd->dev.parent = parent;
49638 new_bd->dev.release = bl_device_release;
49639- dev_set_name(&new_bd->dev, name);
49640+ dev_set_name(&new_bd->dev, "%s", name);
49641 dev_set_drvdata(&new_bd->dev, devdata);
49642
49643 /* Set default properties */
49644diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49645index bca6ccc..252107e 100644
49646--- a/drivers/video/backlight/kb3886_bl.c
49647+++ b/drivers/video/backlight/kb3886_bl.c
49648@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49649 static unsigned long kb3886bl_flags;
49650 #define KB3886BL_SUSPENDED 0x01
49651
49652-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49653+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49654 {
49655 .ident = "Sahara Touch-iT",
49656 .matches = {
49657diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
49658index 34fb6bd..3649fd9 100644
49659--- a/drivers/video/backlight/lcd.c
49660+++ b/drivers/video/backlight/lcd.c
49661@@ -219,7 +219,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,
49662 new_ld->dev.class = lcd_class;
49663 new_ld->dev.parent = parent;
49664 new_ld->dev.release = lcd_device_release;
49665- dev_set_name(&new_ld->dev, name);
49666+ dev_set_name(&new_ld->dev, "%s", name);
49667 dev_set_drvdata(&new_ld->dev, devdata);
49668
49669 rc = device_register(&new_ld->dev);
49670diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49671index 900aa4e..6d49418 100644
49672--- a/drivers/video/fb_defio.c
49673+++ b/drivers/video/fb_defio.c
49674@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49675
49676 BUG_ON(!fbdefio);
49677 mutex_init(&fbdefio->lock);
49678- info->fbops->fb_mmap = fb_deferred_io_mmap;
49679+ pax_open_kernel();
49680+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49681+ pax_close_kernel();
49682 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49683 INIT_LIST_HEAD(&fbdefio->pagelist);
49684 if (fbdefio->delay == 0) /* set a default of 1 s */
49685@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49686 page->mapping = NULL;
49687 }
49688
49689- info->fbops->fb_mmap = NULL;
49690+ *(void **)&info->fbops->fb_mmap = NULL;
49691 mutex_destroy(&fbdefio->lock);
49692 }
49693 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49694diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49695index 5c3960d..15cf8fc 100644
49696--- a/drivers/video/fbcmap.c
49697+++ b/drivers/video/fbcmap.c
49698@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49699 rc = -ENODEV;
49700 goto out;
49701 }
49702- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49703- !info->fbops->fb_setcmap)) {
49704+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49705 rc = -EINVAL;
49706 goto out1;
49707 }
49708diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49709index 098bfc6..796841d 100644
49710--- a/drivers/video/fbmem.c
49711+++ b/drivers/video/fbmem.c
49712@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49713 image->dx += image->width + 8;
49714 }
49715 } else if (rotate == FB_ROTATE_UD) {
49716- for (x = 0; x < num && image->dx >= 0; x++) {
49717+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49718 info->fbops->fb_imageblit(info, image);
49719 image->dx -= image->width + 8;
49720 }
49721@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49722 image->dy += image->height + 8;
49723 }
49724 } else if (rotate == FB_ROTATE_CCW) {
49725- for (x = 0; x < num && image->dy >= 0; x++) {
49726+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49727 info->fbops->fb_imageblit(info, image);
49728 image->dy -= image->height + 8;
49729 }
49730@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49731 return -EFAULT;
49732 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49733 return -EINVAL;
49734- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49735+ if (con2fb.framebuffer >= FB_MAX)
49736 return -EINVAL;
49737 if (!registered_fb[con2fb.framebuffer])
49738 request_module("fb%d", con2fb.framebuffer);
49739diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49740index d4d2c5f..ebbd113 100644
49741--- a/drivers/video/hyperv_fb.c
49742+++ b/drivers/video/hyperv_fb.c
49743@@ -233,7 +233,7 @@ static uint screen_fb_size;
49744 static inline int synthvid_send(struct hv_device *hdev,
49745 struct synthvid_msg *msg)
49746 {
49747- static atomic64_t request_id = ATOMIC64_INIT(0);
49748+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49749 int ret;
49750
49751 msg->pipe_hdr.type = PIPE_MSG_DATA;
49752@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49753
49754 ret = vmbus_sendpacket(hdev->channel, msg,
49755 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49756- atomic64_inc_return(&request_id),
49757+ atomic64_inc_return_unchecked(&request_id),
49758 VM_PKT_DATA_INBAND, 0);
49759
49760 if (ret)
49761diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49762index 7672d2e..b56437f 100644
49763--- a/drivers/video/i810/i810_accel.c
49764+++ b/drivers/video/i810/i810_accel.c
49765@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49766 }
49767 }
49768 printk("ringbuffer lockup!!!\n");
49769+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49770 i810_report_error(mmio);
49771 par->dev_flags |= LOCKUP;
49772 info->pixmap.scan_align = 1;
49773diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49774index 3c14e43..eafa544 100644
49775--- a/drivers/video/logo/logo_linux_clut224.ppm
49776+++ b/drivers/video/logo/logo_linux_clut224.ppm
49777@@ -1,1604 +1,1123 @@
49778 P3
49779-# Standard 224-color Linux logo
49780 80 80
49781 255
49782- 0 0 0 0 0 0 0 0 0 0 0 0
49783- 0 0 0 0 0 0 0 0 0 0 0 0
49784- 0 0 0 0 0 0 0 0 0 0 0 0
49785- 0 0 0 0 0 0 0 0 0 0 0 0
49786- 0 0 0 0 0 0 0 0 0 0 0 0
49787- 0 0 0 0 0 0 0 0 0 0 0 0
49788- 0 0 0 0 0 0 0 0 0 0 0 0
49789- 0 0 0 0 0 0 0 0 0 0 0 0
49790- 0 0 0 0 0 0 0 0 0 0 0 0
49791- 6 6 6 6 6 6 10 10 10 10 10 10
49792- 10 10 10 6 6 6 6 6 6 6 6 6
49793- 0 0 0 0 0 0 0 0 0 0 0 0
49794- 0 0 0 0 0 0 0 0 0 0 0 0
49795- 0 0 0 0 0 0 0 0 0 0 0 0
49796- 0 0 0 0 0 0 0 0 0 0 0 0
49797- 0 0 0 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
49808- 0 0 0 0 0 0 0 0 0 0 0 0
49809- 0 0 0 0 0 0 0 0 0 0 0 0
49810- 0 0 0 6 6 6 10 10 10 14 14 14
49811- 22 22 22 26 26 26 30 30 30 34 34 34
49812- 30 30 30 30 30 30 26 26 26 18 18 18
49813- 14 14 14 10 10 10 6 6 6 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 1 0 0 1 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 0 0 0 0 0 0 0 0 0
49827- 0 0 0 0 0 0 0 0 0 0 0 0
49828- 0 0 0 0 0 0 0 0 0 0 0 0
49829- 0 0 0 0 0 0 0 0 0 0 0 0
49830- 6 6 6 14 14 14 26 26 26 42 42 42
49831- 54 54 54 66 66 66 78 78 78 78 78 78
49832- 78 78 78 74 74 74 66 66 66 54 54 54
49833- 42 42 42 26 26 26 18 18 18 10 10 10
49834- 6 6 6 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 0 0 0 0 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 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
49847- 0 0 0 0 0 0 0 0 0 0 0 0
49848- 0 0 0 0 0 0 0 0 0 0 0 0
49849- 0 0 0 0 0 0 0 0 0 10 10 10
49850- 22 22 22 42 42 42 66 66 66 86 86 86
49851- 66 66 66 38 38 38 38 38 38 22 22 22
49852- 26 26 26 34 34 34 54 54 54 66 66 66
49853- 86 86 86 70 70 70 46 46 46 26 26 26
49854- 14 14 14 6 6 6 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 0 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 1 0 0 1 0 0 1 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 0 0 0
49866- 0 0 0 0 0 0 0 0 0 0 0 0
49867- 0 0 0 0 0 0 0 0 0 0 0 0
49868- 0 0 0 0 0 0 0 0 0 0 0 0
49869- 0 0 0 0 0 0 10 10 10 26 26 26
49870- 50 50 50 82 82 82 58 58 58 6 6 6
49871- 2 2 6 2 2 6 2 2 6 2 2 6
49872- 2 2 6 2 2 6 2 2 6 2 2 6
49873- 6 6 6 54 54 54 86 86 86 66 66 66
49874- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 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 0 0 0 0 0 0
49886- 0 0 0 0 0 0 0 0 0 0 0 0
49887- 0 0 0 0 0 0 0 0 0 0 0 0
49888- 0 0 0 0 0 0 0 0 0 0 0 0
49889- 0 0 0 6 6 6 22 22 22 50 50 50
49890- 78 78 78 34 34 34 2 2 6 2 2 6
49891- 2 2 6 2 2 6 2 2 6 2 2 6
49892- 2 2 6 2 2 6 2 2 6 2 2 6
49893- 2 2 6 2 2 6 6 6 6 70 70 70
49894- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
49904- 0 0 0 0 0 0 0 0 0 0 0 0
49905- 0 0 0 0 0 0 0 0 0 0 0 0
49906- 0 0 0 0 0 0 0 0 0 0 0 0
49907- 0 0 0 0 0 0 0 0 0 0 0 0
49908- 0 0 0 0 0 0 0 0 0 0 0 0
49909- 6 6 6 18 18 18 42 42 42 82 82 82
49910- 26 26 26 2 2 6 2 2 6 2 2 6
49911- 2 2 6 2 2 6 2 2 6 2 2 6
49912- 2 2 6 2 2 6 2 2 6 14 14 14
49913- 46 46 46 34 34 34 6 6 6 2 2 6
49914- 42 42 42 78 78 78 42 42 42 18 18 18
49915- 6 6 6 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 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 0 0 0
49924- 0 0 0 0 0 0 0 0 0 0 0 0
49925- 0 0 0 0 0 0 0 0 0 0 0 0
49926- 0 0 0 0 0 0 0 0 0 0 0 0
49927- 0 0 0 0 0 0 0 0 0 0 0 0
49928- 0 0 0 0 0 0 0 0 0 0 0 0
49929- 10 10 10 30 30 30 66 66 66 58 58 58
49930- 2 2 6 2 2 6 2 2 6 2 2 6
49931- 2 2 6 2 2 6 2 2 6 2 2 6
49932- 2 2 6 2 2 6 2 2 6 26 26 26
49933- 86 86 86 101 101 101 46 46 46 10 10 10
49934- 2 2 6 58 58 58 70 70 70 34 34 34
49935- 10 10 10 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 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
49944- 0 0 0 0 0 0 0 0 0 0 0 0
49945- 0 0 0 0 0 0 0 0 0 0 0 0
49946- 0 0 0 0 0 0 0 0 0 0 0 0
49947- 0 0 0 0 0 0 0 0 0 0 0 0
49948- 0 0 0 0 0 0 0 0 0 0 0 0
49949- 14 14 14 42 42 42 86 86 86 10 10 10
49950- 2 2 6 2 2 6 2 2 6 2 2 6
49951- 2 2 6 2 2 6 2 2 6 2 2 6
49952- 2 2 6 2 2 6 2 2 6 30 30 30
49953- 94 94 94 94 94 94 58 58 58 26 26 26
49954- 2 2 6 6 6 6 78 78 78 54 54 54
49955- 22 22 22 6 6 6 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 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
49966- 0 0 0 0 0 0 0 0 0 0 0 0
49967- 0 0 0 0 0 0 0 0 0 0 0 0
49968- 0 0 0 0 0 0 0 0 0 6 6 6
49969- 22 22 22 62 62 62 62 62 62 2 2 6
49970- 2 2 6 2 2 6 2 2 6 2 2 6
49971- 2 2 6 2 2 6 2 2 6 2 2 6
49972- 2 2 6 2 2 6 2 2 6 26 26 26
49973- 54 54 54 38 38 38 18 18 18 10 10 10
49974- 2 2 6 2 2 6 34 34 34 82 82 82
49975- 38 38 38 14 14 14 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 1 0 0 1 0 0 0
49984- 0 0 0 0 0 0 0 0 0 0 0 0
49985- 0 0 0 0 0 0 0 0 0 0 0 0
49986- 0 0 0 0 0 0 0 0 0 0 0 0
49987- 0 0 0 0 0 0 0 0 0 0 0 0
49988- 0 0 0 0 0 0 0 0 0 6 6 6
49989- 30 30 30 78 78 78 30 30 30 2 2 6
49990- 2 2 6 2 2 6 2 2 6 2 2 6
49991- 2 2 6 2 2 6 2 2 6 2 2 6
49992- 2 2 6 2 2 6 2 2 6 10 10 10
49993- 10 10 10 2 2 6 2 2 6 2 2 6
49994- 2 2 6 2 2 6 2 2 6 78 78 78
49995- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
50004- 0 0 0 0 0 0 0 0 0 0 0 0
50005- 0 0 0 0 0 0 0 0 0 0 0 0
50006- 0 0 0 0 0 0 0 0 0 0 0 0
50007- 0 0 0 0 0 0 0 0 0 0 0 0
50008- 0 0 0 0 0 0 0 0 0 10 10 10
50009- 38 38 38 86 86 86 14 14 14 2 2 6
50010- 2 2 6 2 2 6 2 2 6 2 2 6
50011- 2 2 6 2 2 6 2 2 6 2 2 6
50012- 2 2 6 2 2 6 2 2 6 2 2 6
50013- 2 2 6 2 2 6 2 2 6 2 2 6
50014- 2 2 6 2 2 6 2 2 6 54 54 54
50015- 66 66 66 26 26 26 6 6 6 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 0 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 1 0 0 1 0 0 0
50024- 0 0 0 0 0 0 0 0 0 0 0 0
50025- 0 0 0 0 0 0 0 0 0 0 0 0
50026- 0 0 0 0 0 0 0 0 0 0 0 0
50027- 0 0 0 0 0 0 0 0 0 0 0 0
50028- 0 0 0 0 0 0 0 0 0 14 14 14
50029- 42 42 42 82 82 82 2 2 6 2 2 6
50030- 2 2 6 6 6 6 10 10 10 2 2 6
50031- 2 2 6 2 2 6 2 2 6 2 2 6
50032- 2 2 6 2 2 6 2 2 6 6 6 6
50033- 14 14 14 10 10 10 2 2 6 2 2 6
50034- 2 2 6 2 2 6 2 2 6 18 18 18
50035- 82 82 82 34 34 34 10 10 10 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 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
50044- 0 0 0 0 0 0 0 0 0 0 0 0
50045- 0 0 0 0 0 0 0 0 0 0 0 0
50046- 0 0 0 0 0 0 0 0 0 0 0 0
50047- 0 0 0 0 0 0 0 0 0 0 0 0
50048- 0 0 0 0 0 0 0 0 0 14 14 14
50049- 46 46 46 86 86 86 2 2 6 2 2 6
50050- 6 6 6 6 6 6 22 22 22 34 34 34
50051- 6 6 6 2 2 6 2 2 6 2 2 6
50052- 2 2 6 2 2 6 18 18 18 34 34 34
50053- 10 10 10 50 50 50 22 22 22 2 2 6
50054- 2 2 6 2 2 6 2 2 6 10 10 10
50055- 86 86 86 42 42 42 14 14 14 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 0 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 1 0 0 1 0 0 1 0 0 0
50064- 0 0 0 0 0 0 0 0 0 0 0 0
50065- 0 0 0 0 0 0 0 0 0 0 0 0
50066- 0 0 0 0 0 0 0 0 0 0 0 0
50067- 0 0 0 0 0 0 0 0 0 0 0 0
50068- 0 0 0 0 0 0 0 0 0 14 14 14
50069- 46 46 46 86 86 86 2 2 6 2 2 6
50070- 38 38 38 116 116 116 94 94 94 22 22 22
50071- 22 22 22 2 2 6 2 2 6 2 2 6
50072- 14 14 14 86 86 86 138 138 138 162 162 162
50073-154 154 154 38 38 38 26 26 26 6 6 6
50074- 2 2 6 2 2 6 2 2 6 2 2 6
50075- 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 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 0 0 0
50085- 0 0 0 0 0 0 0 0 0 0 0 0
50086- 0 0 0 0 0 0 0 0 0 0 0 0
50087- 0 0 0 0 0 0 0 0 0 0 0 0
50088- 0 0 0 0 0 0 0 0 0 14 14 14
50089- 46 46 46 86 86 86 2 2 6 14 14 14
50090-134 134 134 198 198 198 195 195 195 116 116 116
50091- 10 10 10 2 2 6 2 2 6 6 6 6
50092-101 98 89 187 187 187 210 210 210 218 218 218
50093-214 214 214 134 134 134 14 14 14 6 6 6
50094- 2 2 6 2 2 6 2 2 6 2 2 6
50095- 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
50103- 0 0 1 0 0 1 0 0 1 0 0 0
50104- 0 0 0 0 0 0 0 0 0 0 0 0
50105- 0 0 0 0 0 0 0 0 0 0 0 0
50106- 0 0 0 0 0 0 0 0 0 0 0 0
50107- 0 0 0 0 0 0 0 0 0 0 0 0
50108- 0 0 0 0 0 0 0 0 0 14 14 14
50109- 46 46 46 86 86 86 2 2 6 54 54 54
50110-218 218 218 195 195 195 226 226 226 246 246 246
50111- 58 58 58 2 2 6 2 2 6 30 30 30
50112-210 210 210 253 253 253 174 174 174 123 123 123
50113-221 221 221 234 234 234 74 74 74 2 2 6
50114- 2 2 6 2 2 6 2 2 6 2 2 6
50115- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0
50119- 0 0 0 0 0 0 0 0 0 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 0 0 0
50125- 0 0 0 0 0 0 0 0 0 0 0 0
50126- 0 0 0 0 0 0 0 0 0 0 0 0
50127- 0 0 0 0 0 0 0 0 0 0 0 0
50128- 0 0 0 0 0 0 0 0 0 14 14 14
50129- 46 46 46 82 82 82 2 2 6 106 106 106
50130-170 170 170 26 26 26 86 86 86 226 226 226
50131-123 123 123 10 10 10 14 14 14 46 46 46
50132-231 231 231 190 190 190 6 6 6 70 70 70
50133- 90 90 90 238 238 238 158 158 158 2 2 6
50134- 2 2 6 2 2 6 2 2 6 2 2 6
50135- 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
50143- 0 0 1 0 0 1 0 0 1 0 0 0
50144- 0 0 0 0 0 0 0 0 0 0 0 0
50145- 0 0 0 0 0 0 0 0 0 0 0 0
50146- 0 0 0 0 0 0 0 0 0 0 0 0
50147- 0 0 0 0 0 0 0 0 0 0 0 0
50148- 0 0 0 0 0 0 0 0 0 14 14 14
50149- 42 42 42 86 86 86 6 6 6 116 116 116
50150-106 106 106 6 6 6 70 70 70 149 149 149
50151-128 128 128 18 18 18 38 38 38 54 54 54
50152-221 221 221 106 106 106 2 2 6 14 14 14
50153- 46 46 46 190 190 190 198 198 198 2 2 6
50154- 2 2 6 2 2 6 2 2 6 2 2 6
50155- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0
50159- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
50163- 0 0 1 0 0 0 0 0 1 0 0 0
50164- 0 0 0 0 0 0 0 0 0 0 0 0
50165- 0 0 0 0 0 0 0 0 0 0 0 0
50166- 0 0 0 0 0 0 0 0 0 0 0 0
50167- 0 0 0 0 0 0 0 0 0 0 0 0
50168- 0 0 0 0 0 0 0 0 0 14 14 14
50169- 42 42 42 94 94 94 14 14 14 101 101 101
50170-128 128 128 2 2 6 18 18 18 116 116 116
50171-118 98 46 121 92 8 121 92 8 98 78 10
50172-162 162 162 106 106 106 2 2 6 2 2 6
50173- 2 2 6 195 195 195 195 195 195 6 6 6
50174- 2 2 6 2 2 6 2 2 6 2 2 6
50175- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0
50179- 0 0 0 0 0 0 0 0 0 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 1 0 0 1
50183- 0 0 1 0 0 0 0 0 1 0 0 0
50184- 0 0 0 0 0 0 0 0 0 0 0 0
50185- 0 0 0 0 0 0 0 0 0 0 0 0
50186- 0 0 0 0 0 0 0 0 0 0 0 0
50187- 0 0 0 0 0 0 0 0 0 0 0 0
50188- 0 0 0 0 0 0 0 0 0 10 10 10
50189- 38 38 38 90 90 90 14 14 14 58 58 58
50190-210 210 210 26 26 26 54 38 6 154 114 10
50191-226 170 11 236 186 11 225 175 15 184 144 12
50192-215 174 15 175 146 61 37 26 9 2 2 6
50193- 70 70 70 246 246 246 138 138 138 2 2 6
50194- 2 2 6 2 2 6 2 2 6 2 2 6
50195- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0 0
50199- 0 0 0 0 0 0 0 0 0 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 0 0 0
50205- 0 0 0 0 0 0 0 0 0 0 0 0
50206- 0 0 0 0 0 0 0 0 0 0 0 0
50207- 0 0 0 0 0 0 0 0 0 0 0 0
50208- 0 0 0 0 0 0 0 0 0 10 10 10
50209- 38 38 38 86 86 86 14 14 14 10 10 10
50210-195 195 195 188 164 115 192 133 9 225 175 15
50211-239 182 13 234 190 10 232 195 16 232 200 30
50212-245 207 45 241 208 19 232 195 16 184 144 12
50213-218 194 134 211 206 186 42 42 42 2 2 6
50214- 2 2 6 2 2 6 2 2 6 2 2 6
50215- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
50225- 0 0 0 0 0 0 0 0 0 0 0 0
50226- 0 0 0 0 0 0 0 0 0 0 0 0
50227- 0 0 0 0 0 0 0 0 0 0 0 0
50228- 0 0 0 0 0 0 0 0 0 10 10 10
50229- 34 34 34 86 86 86 14 14 14 2 2 6
50230-121 87 25 192 133 9 219 162 10 239 182 13
50231-236 186 11 232 195 16 241 208 19 244 214 54
50232-246 218 60 246 218 38 246 215 20 241 208 19
50233-241 208 19 226 184 13 121 87 25 2 2 6
50234- 2 2 6 2 2 6 2 2 6 2 2 6
50235- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
50245- 0 0 0 0 0 0 0 0 0 0 0 0
50246- 0 0 0 0 0 0 0 0 0 0 0 0
50247- 0 0 0 0 0 0 0 0 0 0 0 0
50248- 0 0 0 0 0 0 0 0 0 10 10 10
50249- 34 34 34 82 82 82 30 30 30 61 42 6
50250-180 123 7 206 145 10 230 174 11 239 182 13
50251-234 190 10 238 202 15 241 208 19 246 218 74
50252-246 218 38 246 215 20 246 215 20 246 215 20
50253-226 184 13 215 174 15 184 144 12 6 6 6
50254- 2 2 6 2 2 6 2 2 6 2 2 6
50255- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
50265- 0 0 0 0 0 0 0 0 0 0 0 0
50266- 0 0 0 0 0 0 0 0 0 0 0 0
50267- 0 0 0 0 0 0 0 0 0 0 0 0
50268- 0 0 0 0 0 0 0 0 0 10 10 10
50269- 30 30 30 78 78 78 50 50 50 104 69 6
50270-192 133 9 216 158 10 236 178 12 236 186 11
50271-232 195 16 241 208 19 244 214 54 245 215 43
50272-246 215 20 246 215 20 241 208 19 198 155 10
50273-200 144 11 216 158 10 156 118 10 2 2 6
50274- 2 2 6 2 2 6 2 2 6 2 2 6
50275- 6 6 6 90 90 90 54 54 54 18 18 18
50276- 6 6 6 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 0 0 0
50285- 0 0 0 0 0 0 0 0 0 0 0 0
50286- 0 0 0 0 0 0 0 0 0 0 0 0
50287- 0 0 0 0 0 0 0 0 0 0 0 0
50288- 0 0 0 0 0 0 0 0 0 10 10 10
50289- 30 30 30 78 78 78 46 46 46 22 22 22
50290-137 92 6 210 162 10 239 182 13 238 190 10
50291-238 202 15 241 208 19 246 215 20 246 215 20
50292-241 208 19 203 166 17 185 133 11 210 150 10
50293-216 158 10 210 150 10 102 78 10 2 2 6
50294- 6 6 6 54 54 54 14 14 14 2 2 6
50295- 2 2 6 62 62 62 74 74 74 30 30 30
50296- 10 10 10 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 0 0 0
50305- 0 0 0 0 0 0 0 0 0 0 0 0
50306- 0 0 0 0 0 0 0 0 0 0 0 0
50307- 0 0 0 0 0 0 0 0 0 0 0 0
50308- 0 0 0 0 0 0 0 0 0 10 10 10
50309- 34 34 34 78 78 78 50 50 50 6 6 6
50310- 94 70 30 139 102 15 190 146 13 226 184 13
50311-232 200 30 232 195 16 215 174 15 190 146 13
50312-168 122 10 192 133 9 210 150 10 213 154 11
50313-202 150 34 182 157 106 101 98 89 2 2 6
50314- 2 2 6 78 78 78 116 116 116 58 58 58
50315- 2 2 6 22 22 22 90 90 90 46 46 46
50316- 18 18 18 6 6 6 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 0 0 0
50325- 0 0 0 0 0 0 0 0 0 0 0 0
50326- 0 0 0 0 0 0 0 0 0 0 0 0
50327- 0 0 0 0 0 0 0 0 0 0 0 0
50328- 0 0 0 0 0 0 0 0 0 10 10 10
50329- 38 38 38 86 86 86 50 50 50 6 6 6
50330-128 128 128 174 154 114 156 107 11 168 122 10
50331-198 155 10 184 144 12 197 138 11 200 144 11
50332-206 145 10 206 145 10 197 138 11 188 164 115
50333-195 195 195 198 198 198 174 174 174 14 14 14
50334- 2 2 6 22 22 22 116 116 116 116 116 116
50335- 22 22 22 2 2 6 74 74 74 70 70 70
50336- 30 30 30 10 10 10 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 0 0 0
50345- 0 0 0 0 0 0 0 0 0 0 0 0
50346- 0 0 0 0 0 0 0 0 0 0 0 0
50347- 0 0 0 0 0 0 0 0 0 0 0 0
50348- 0 0 0 0 0 0 6 6 6 18 18 18
50349- 50 50 50 101 101 101 26 26 26 10 10 10
50350-138 138 138 190 190 190 174 154 114 156 107 11
50351-197 138 11 200 144 11 197 138 11 192 133 9
50352-180 123 7 190 142 34 190 178 144 187 187 187
50353-202 202 202 221 221 221 214 214 214 66 66 66
50354- 2 2 6 2 2 6 50 50 50 62 62 62
50355- 6 6 6 2 2 6 10 10 10 90 90 90
50356- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
50365- 0 0 0 0 0 0 0 0 0 0 0 0
50366- 0 0 0 0 0 0 0 0 0 0 0 0
50367- 0 0 0 0 0 0 0 0 0 0 0 0
50368- 0 0 0 0 0 0 10 10 10 34 34 34
50369- 74 74 74 74 74 74 2 2 6 6 6 6
50370-144 144 144 198 198 198 190 190 190 178 166 146
50371-154 121 60 156 107 11 156 107 11 168 124 44
50372-174 154 114 187 187 187 190 190 190 210 210 210
50373-246 246 246 253 253 253 253 253 253 182 182 182
50374- 6 6 6 2 2 6 2 2 6 2 2 6
50375- 2 2 6 2 2 6 2 2 6 62 62 62
50376- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0
50385- 0 0 0 0 0 0 0 0 0 0 0 0
50386- 0 0 0 0 0 0 0 0 0 0 0 0
50387- 0 0 0 0 0 0 0 0 0 0 0 0
50388- 0 0 0 10 10 10 22 22 22 54 54 54
50389- 94 94 94 18 18 18 2 2 6 46 46 46
50390-234 234 234 221 221 221 190 190 190 190 190 190
50391-190 190 190 187 187 187 187 187 187 190 190 190
50392-190 190 190 195 195 195 214 214 214 242 242 242
50393-253 253 253 253 253 253 253 253 253 253 253 253
50394- 82 82 82 2 2 6 2 2 6 2 2 6
50395- 2 2 6 2 2 6 2 2 6 14 14 14
50396- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
50405- 0 0 0 0 0 0 0 0 0 0 0 0
50406- 0 0 0 0 0 0 0 0 0 0 0 0
50407- 0 0 0 0 0 0 0 0 0 0 0 0
50408- 6 6 6 18 18 18 46 46 46 90 90 90
50409- 46 46 46 18 18 18 6 6 6 182 182 182
50410-253 253 253 246 246 246 206 206 206 190 190 190
50411-190 190 190 190 190 190 190 190 190 190 190 190
50412-206 206 206 231 231 231 250 250 250 253 253 253
50413-253 253 253 253 253 253 253 253 253 253 253 253
50414-202 202 202 14 14 14 2 2 6 2 2 6
50415- 2 2 6 2 2 6 2 2 6 2 2 6
50416- 42 42 42 86 86 86 42 42 42 18 18 18
50417- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50425- 0 0 0 0 0 0 0 0 0 0 0 0
50426- 0 0 0 0 0 0 0 0 0 0 0 0
50427- 0 0 0 0 0 0 0 0 0 6 6 6
50428- 14 14 14 38 38 38 74 74 74 66 66 66
50429- 2 2 6 6 6 6 90 90 90 250 250 250
50430-253 253 253 253 253 253 238 238 238 198 198 198
50431-190 190 190 190 190 190 195 195 195 221 221 221
50432-246 246 246 253 253 253 253 253 253 253 253 253
50433-253 253 253 253 253 253 253 253 253 253 253 253
50434-253 253 253 82 82 82 2 2 6 2 2 6
50435- 2 2 6 2 2 6 2 2 6 2 2 6
50436- 2 2 6 78 78 78 70 70 70 34 34 34
50437- 14 14 14 6 6 6 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 0 0 0
50444- 0 0 0 0 0 0 0 0 0 0 0 0
50445- 0 0 0 0 0 0 0 0 0 0 0 0
50446- 0 0 0 0 0 0 0 0 0 0 0 0
50447- 0 0 0 0 0 0 0 0 0 14 14 14
50448- 34 34 34 66 66 66 78 78 78 6 6 6
50449- 2 2 6 18 18 18 218 218 218 253 253 253
50450-253 253 253 253 253 253 253 253 253 246 246 246
50451-226 226 226 231 231 231 246 246 246 253 253 253
50452-253 253 253 253 253 253 253 253 253 253 253 253
50453-253 253 253 253 253 253 253 253 253 253 253 253
50454-253 253 253 178 178 178 2 2 6 2 2 6
50455- 2 2 6 2 2 6 2 2 6 2 2 6
50456- 2 2 6 18 18 18 90 90 90 62 62 62
50457- 30 30 30 10 10 10 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 0 0 0
50464- 0 0 0 0 0 0 0 0 0 0 0 0
50465- 0 0 0 0 0 0 0 0 0 0 0 0
50466- 0 0 0 0 0 0 0 0 0 0 0 0
50467- 0 0 0 0 0 0 10 10 10 26 26 26
50468- 58 58 58 90 90 90 18 18 18 2 2 6
50469- 2 2 6 110 110 110 253 253 253 253 253 253
50470-253 253 253 253 253 253 253 253 253 253 253 253
50471-250 250 250 253 253 253 253 253 253 253 253 253
50472-253 253 253 253 253 253 253 253 253 253 253 253
50473-253 253 253 253 253 253 253 253 253 253 253 253
50474-253 253 253 231 231 231 18 18 18 2 2 6
50475- 2 2 6 2 2 6 2 2 6 2 2 6
50476- 2 2 6 2 2 6 18 18 18 94 94 94
50477- 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0
50484- 0 0 0 0 0 0 0 0 0 0 0 0
50485- 0 0 0 0 0 0 0 0 0 0 0 0
50486- 0 0 0 0 0 0 0 0 0 0 0 0
50487- 0 0 0 6 6 6 22 22 22 50 50 50
50488- 90 90 90 26 26 26 2 2 6 2 2 6
50489- 14 14 14 195 195 195 250 250 250 253 253 253
50490-253 253 253 253 253 253 253 253 253 253 253 253
50491-253 253 253 253 253 253 253 253 253 253 253 253
50492-253 253 253 253 253 253 253 253 253 253 253 253
50493-253 253 253 253 253 253 253 253 253 253 253 253
50494-250 250 250 242 242 242 54 54 54 2 2 6
50495- 2 2 6 2 2 6 2 2 6 2 2 6
50496- 2 2 6 2 2 6 2 2 6 38 38 38
50497- 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
50504- 0 0 0 0 0 0 0 0 0 0 0 0
50505- 0 0 0 0 0 0 0 0 0 0 0 0
50506- 0 0 0 0 0 0 0 0 0 0 0 0
50507- 6 6 6 14 14 14 38 38 38 82 82 82
50508- 34 34 34 2 2 6 2 2 6 2 2 6
50509- 42 42 42 195 195 195 246 246 246 253 253 253
50510-253 253 253 253 253 253 253 253 253 250 250 250
50511-242 242 242 242 242 242 250 250 250 253 253 253
50512-253 253 253 253 253 253 253 253 253 253 253 253
50513-253 253 253 250 250 250 246 246 246 238 238 238
50514-226 226 226 231 231 231 101 101 101 6 6 6
50515- 2 2 6 2 2 6 2 2 6 2 2 6
50516- 2 2 6 2 2 6 2 2 6 2 2 6
50517- 38 38 38 82 82 82 42 42 42 14 14 14
50518- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50524- 0 0 0 0 0 0 0 0 0 0 0 0
50525- 0 0 0 0 0 0 0 0 0 0 0 0
50526- 0 0 0 0 0 0 0 0 0 0 0 0
50527- 10 10 10 26 26 26 62 62 62 66 66 66
50528- 2 2 6 2 2 6 2 2 6 6 6 6
50529- 70 70 70 170 170 170 206 206 206 234 234 234
50530-246 246 246 250 250 250 250 250 250 238 238 238
50531-226 226 226 231 231 231 238 238 238 250 250 250
50532-250 250 250 250 250 250 246 246 246 231 231 231
50533-214 214 214 206 206 206 202 202 202 202 202 202
50534-198 198 198 202 202 202 182 182 182 18 18 18
50535- 2 2 6 2 2 6 2 2 6 2 2 6
50536- 2 2 6 2 2 6 2 2 6 2 2 6
50537- 2 2 6 62 62 62 66 66 66 30 30 30
50538- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
50544- 0 0 0 0 0 0 0 0 0 0 0 0
50545- 0 0 0 0 0 0 0 0 0 0 0 0
50546- 0 0 0 0 0 0 0 0 0 0 0 0
50547- 14 14 14 42 42 42 82 82 82 18 18 18
50548- 2 2 6 2 2 6 2 2 6 10 10 10
50549- 94 94 94 182 182 182 218 218 218 242 242 242
50550-250 250 250 253 253 253 253 253 253 250 250 250
50551-234 234 234 253 253 253 253 253 253 253 253 253
50552-253 253 253 253 253 253 253 253 253 246 246 246
50553-238 238 238 226 226 226 210 210 210 202 202 202
50554-195 195 195 195 195 195 210 210 210 158 158 158
50555- 6 6 6 14 14 14 50 50 50 14 14 14
50556- 2 2 6 2 2 6 2 2 6 2 2 6
50557- 2 2 6 6 6 6 86 86 86 46 46 46
50558- 18 18 18 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50564- 0 0 0 0 0 0 0 0 0 0 0 0
50565- 0 0 0 0 0 0 0 0 0 0 0 0
50566- 0 0 0 0 0 0 0 0 0 6 6 6
50567- 22 22 22 54 54 54 70 70 70 2 2 6
50568- 2 2 6 10 10 10 2 2 6 22 22 22
50569-166 166 166 231 231 231 250 250 250 253 253 253
50570-253 253 253 253 253 253 253 253 253 250 250 250
50571-242 242 242 253 253 253 253 253 253 253 253 253
50572-253 253 253 253 253 253 253 253 253 253 253 253
50573-253 253 253 253 253 253 253 253 253 246 246 246
50574-231 231 231 206 206 206 198 198 198 226 226 226
50575- 94 94 94 2 2 6 6 6 6 38 38 38
50576- 30 30 30 2 2 6 2 2 6 2 2 6
50577- 2 2 6 2 2 6 62 62 62 66 66 66
50578- 26 26 26 10 10 10 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 0 0 0
50583- 0 0 0 0 0 0 0 0 0 0 0 0
50584- 0 0 0 0 0 0 0 0 0 0 0 0
50585- 0 0 0 0 0 0 0 0 0 0 0 0
50586- 0 0 0 0 0 0 0 0 0 10 10 10
50587- 30 30 30 74 74 74 50 50 50 2 2 6
50588- 26 26 26 26 26 26 2 2 6 106 106 106
50589-238 238 238 253 253 253 253 253 253 253 253 253
50590-253 253 253 253 253 253 253 253 253 253 253 253
50591-253 253 253 253 253 253 253 253 253 253 253 253
50592-253 253 253 253 253 253 253 253 253 253 253 253
50593-253 253 253 253 253 253 253 253 253 253 253 253
50594-253 253 253 246 246 246 218 218 218 202 202 202
50595-210 210 210 14 14 14 2 2 6 2 2 6
50596- 30 30 30 22 22 22 2 2 6 2 2 6
50597- 2 2 6 2 2 6 18 18 18 86 86 86
50598- 42 42 42 14 14 14 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 0 0 0
50603- 0 0 0 0 0 0 0 0 0 0 0 0
50604- 0 0 0 0 0 0 0 0 0 0 0 0
50605- 0 0 0 0 0 0 0 0 0 0 0 0
50606- 0 0 0 0 0 0 0 0 0 14 14 14
50607- 42 42 42 90 90 90 22 22 22 2 2 6
50608- 42 42 42 2 2 6 18 18 18 218 218 218
50609-253 253 253 253 253 253 253 253 253 253 253 253
50610-253 253 253 253 253 253 253 253 253 253 253 253
50611-253 253 253 253 253 253 253 253 253 253 253 253
50612-253 253 253 253 253 253 253 253 253 253 253 253
50613-253 253 253 253 253 253 253 253 253 253 253 253
50614-253 253 253 253 253 253 250 250 250 221 221 221
50615-218 218 218 101 101 101 2 2 6 14 14 14
50616- 18 18 18 38 38 38 10 10 10 2 2 6
50617- 2 2 6 2 2 6 2 2 6 78 78 78
50618- 58 58 58 22 22 22 6 6 6 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 0 0 0
50623- 0 0 0 0 0 0 0 0 0 0 0 0
50624- 0 0 0 0 0 0 0 0 0 0 0 0
50625- 0 0 0 0 0 0 0 0 0 0 0 0
50626- 0 0 0 0 0 0 6 6 6 18 18 18
50627- 54 54 54 82 82 82 2 2 6 26 26 26
50628- 22 22 22 2 2 6 123 123 123 253 253 253
50629-253 253 253 253 253 253 253 253 253 253 253 253
50630-253 253 253 253 253 253 253 253 253 253 253 253
50631-253 253 253 253 253 253 253 253 253 253 253 253
50632-253 253 253 253 253 253 253 253 253 253 253 253
50633-253 253 253 253 253 253 253 253 253 253 253 253
50634-253 253 253 253 253 253 253 253 253 250 250 250
50635-238 238 238 198 198 198 6 6 6 38 38 38
50636- 58 58 58 26 26 26 38 38 38 2 2 6
50637- 2 2 6 2 2 6 2 2 6 46 46 46
50638- 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0
50643- 0 0 0 0 0 0 0 0 0 0 0 0
50644- 0 0 0 0 0 0 0 0 0 0 0 0
50645- 0 0 0 0 0 0 0 0 0 0 0 0
50646- 0 0 0 0 0 0 10 10 10 30 30 30
50647- 74 74 74 58 58 58 2 2 6 42 42 42
50648- 2 2 6 22 22 22 231 231 231 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-253 253 253 253 253 253 253 253 253 253 253 253
50652-253 253 253 253 253 253 253 253 253 253 253 253
50653-253 253 253 253 253 253 253 253 253 253 253 253
50654-253 253 253 253 253 253 253 253 253 253 253 253
50655-253 253 253 246 246 246 46 46 46 38 38 38
50656- 42 42 42 14 14 14 38 38 38 14 14 14
50657- 2 2 6 2 2 6 2 2 6 6 6 6
50658- 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
50663- 0 0 0 0 0 0 0 0 0 0 0 0
50664- 0 0 0 0 0 0 0 0 0 0 0 0
50665- 0 0 0 0 0 0 0 0 0 0 0 0
50666- 0 0 0 6 6 6 14 14 14 42 42 42
50667- 90 90 90 18 18 18 18 18 18 26 26 26
50668- 2 2 6 116 116 116 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 250 250 250 238 238 238
50671-253 253 253 253 253 253 253 253 253 253 253 253
50672-253 253 253 253 253 253 253 253 253 253 253 253
50673-253 253 253 253 253 253 253 253 253 253 253 253
50674-253 253 253 253 253 253 253 253 253 253 253 253
50675-253 253 253 253 253 253 94 94 94 6 6 6
50676- 2 2 6 2 2 6 10 10 10 34 34 34
50677- 2 2 6 2 2 6 2 2 6 2 2 6
50678- 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
50683- 0 0 0 0 0 0 0 0 0 0 0 0
50684- 0 0 0 0 0 0 0 0 0 0 0 0
50685- 0 0 0 0 0 0 0 0 0 0 0 0
50686- 0 0 0 10 10 10 26 26 26 66 66 66
50687- 82 82 82 2 2 6 38 38 38 6 6 6
50688- 14 14 14 210 210 210 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 246 246 246 242 242 242
50691-253 253 253 253 253 253 253 253 253 253 253 253
50692-253 253 253 253 253 253 253 253 253 253 253 253
50693-253 253 253 253 253 253 253 253 253 253 253 253
50694-253 253 253 253 253 253 253 253 253 253 253 253
50695-253 253 253 253 253 253 144 144 144 2 2 6
50696- 2 2 6 2 2 6 2 2 6 46 46 46
50697- 2 2 6 2 2 6 2 2 6 2 2 6
50698- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0 0 0 0
50703- 0 0 0 0 0 0 0 0 0 0 0 0
50704- 0 0 0 0 0 0 0 0 0 0 0 0
50705- 0 0 0 0 0 0 0 0 0 0 0 0
50706- 6 6 6 14 14 14 42 42 42 90 90 90
50707- 26 26 26 6 6 6 42 42 42 2 2 6
50708- 74 74 74 250 250 250 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 242 242 242 242 242 242
50711-253 253 253 253 253 253 253 253 253 253 253 253
50712-253 253 253 253 253 253 253 253 253 253 253 253
50713-253 253 253 253 253 253 253 253 253 253 253 253
50714-253 253 253 253 253 253 253 253 253 253 253 253
50715-253 253 253 253 253 253 182 182 182 2 2 6
50716- 2 2 6 2 2 6 2 2 6 46 46 46
50717- 2 2 6 2 2 6 2 2 6 2 2 6
50718- 10 10 10 86 86 86 38 38 38 10 10 10
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- 0 0 0 0 0 0 0 0 0 0 0 0
50723- 0 0 0 0 0 0 0 0 0 0 0 0
50724- 0 0 0 0 0 0 0 0 0 0 0 0
50725- 0 0 0 0 0 0 0 0 0 0 0 0
50726- 10 10 10 26 26 26 66 66 66 82 82 82
50727- 2 2 6 22 22 22 18 18 18 2 2 6
50728-149 149 149 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 234 234 234 242 242 242
50731-253 253 253 253 253 253 253 253 253 253 253 253
50732-253 253 253 253 253 253 253 253 253 253 253 253
50733-253 253 253 253 253 253 253 253 253 253 253 253
50734-253 253 253 253 253 253 253 253 253 253 253 253
50735-253 253 253 253 253 253 206 206 206 2 2 6
50736- 2 2 6 2 2 6 2 2 6 38 38 38
50737- 2 2 6 2 2 6 2 2 6 2 2 6
50738- 6 6 6 86 86 86 46 46 46 14 14 14
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- 0 0 0 0 0 0 0 0 0 0 0 0
50743- 0 0 0 0 0 0 0 0 0 0 0 0
50744- 0 0 0 0 0 0 0 0 0 0 0 0
50745- 0 0 0 0 0 0 0 0 0 6 6 6
50746- 18 18 18 46 46 46 86 86 86 18 18 18
50747- 2 2 6 34 34 34 10 10 10 6 6 6
50748-210 210 210 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 234 234 234 242 242 242
50751-253 253 253 253 253 253 253 253 253 253 253 253
50752-253 253 253 253 253 253 253 253 253 253 253 253
50753-253 253 253 253 253 253 253 253 253 253 253 253
50754-253 253 253 253 253 253 253 253 253 253 253 253
50755-253 253 253 253 253 253 221 221 221 6 6 6
50756- 2 2 6 2 2 6 6 6 6 30 30 30
50757- 2 2 6 2 2 6 2 2 6 2 2 6
50758- 2 2 6 82 82 82 54 54 54 18 18 18
50759- 6 6 6 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 0 0 0
50762- 0 0 0 0 0 0 0 0 0 0 0 0
50763- 0 0 0 0 0 0 0 0 0 0 0 0
50764- 0 0 0 0 0 0 0 0 0 0 0 0
50765- 0 0 0 0 0 0 0 0 0 10 10 10
50766- 26 26 26 66 66 66 62 62 62 2 2 6
50767- 2 2 6 38 38 38 10 10 10 26 26 26
50768-238 238 238 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 231 231 231 238 238 238
50771-253 253 253 253 253 253 253 253 253 253 253 253
50772-253 253 253 253 253 253 253 253 253 253 253 253
50773-253 253 253 253 253 253 253 253 253 253 253 253
50774-253 253 253 253 253 253 253 253 253 253 253 253
50775-253 253 253 253 253 253 231 231 231 6 6 6
50776- 2 2 6 2 2 6 10 10 10 30 30 30
50777- 2 2 6 2 2 6 2 2 6 2 2 6
50778- 2 2 6 66 66 66 58 58 58 22 22 22
50779- 6 6 6 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 0 0 0
50782- 0 0 0 0 0 0 0 0 0 0 0 0
50783- 0 0 0 0 0 0 0 0 0 0 0 0
50784- 0 0 0 0 0 0 0 0 0 0 0 0
50785- 0 0 0 0 0 0 0 0 0 10 10 10
50786- 38 38 38 78 78 78 6 6 6 2 2 6
50787- 2 2 6 46 46 46 14 14 14 42 42 42
50788-246 246 246 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 231 231 231 242 242 242
50791-253 253 253 253 253 253 253 253 253 253 253 253
50792-253 253 253 253 253 253 253 253 253 253 253 253
50793-253 253 253 253 253 253 253 253 253 253 253 253
50794-253 253 253 253 253 253 253 253 253 253 253 253
50795-253 253 253 253 253 253 234 234 234 10 10 10
50796- 2 2 6 2 2 6 22 22 22 14 14 14
50797- 2 2 6 2 2 6 2 2 6 2 2 6
50798- 2 2 6 66 66 66 62 62 62 22 22 22
50799- 6 6 6 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 0 0 0
50802- 0 0 0 0 0 0 0 0 0 0 0 0
50803- 0 0 0 0 0 0 0 0 0 0 0 0
50804- 0 0 0 0 0 0 0 0 0 0 0 0
50805- 0 0 0 0 0 0 6 6 6 18 18 18
50806- 50 50 50 74 74 74 2 2 6 2 2 6
50807- 14 14 14 70 70 70 34 34 34 62 62 62
50808-250 250 250 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 231 231 231 246 246 246
50811-253 253 253 253 253 253 253 253 253 253 253 253
50812-253 253 253 253 253 253 253 253 253 253 253 253
50813-253 253 253 253 253 253 253 253 253 253 253 253
50814-253 253 253 253 253 253 253 253 253 253 253 253
50815-253 253 253 253 253 253 234 234 234 14 14 14
50816- 2 2 6 2 2 6 30 30 30 2 2 6
50817- 2 2 6 2 2 6 2 2 6 2 2 6
50818- 2 2 6 66 66 66 62 62 62 22 22 22
50819- 6 6 6 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 0 0 0 0 0 0
50822- 0 0 0 0 0 0 0 0 0 0 0 0
50823- 0 0 0 0 0 0 0 0 0 0 0 0
50824- 0 0 0 0 0 0 0 0 0 0 0 0
50825- 0 0 0 0 0 0 6 6 6 18 18 18
50826- 54 54 54 62 62 62 2 2 6 2 2 6
50827- 2 2 6 30 30 30 46 46 46 70 70 70
50828-250 250 250 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 231 231 231 246 246 246
50831-253 253 253 253 253 253 253 253 253 253 253 253
50832-253 253 253 253 253 253 253 253 253 253 253 253
50833-253 253 253 253 253 253 253 253 253 253 253 253
50834-253 253 253 253 253 253 253 253 253 253 253 253
50835-253 253 253 253 253 253 226 226 226 10 10 10
50836- 2 2 6 6 6 6 30 30 30 2 2 6
50837- 2 2 6 2 2 6 2 2 6 2 2 6
50838- 2 2 6 66 66 66 58 58 58 22 22 22
50839- 6 6 6 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 0 0 0 0 0 0
50842- 0 0 0 0 0 0 0 0 0 0 0 0
50843- 0 0 0 0 0 0 0 0 0 0 0 0
50844- 0 0 0 0 0 0 0 0 0 0 0 0
50845- 0 0 0 0 0 0 6 6 6 22 22 22
50846- 58 58 58 62 62 62 2 2 6 2 2 6
50847- 2 2 6 2 2 6 30 30 30 78 78 78
50848-250 250 250 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 231 231 231 246 246 246
50851-253 253 253 253 253 253 253 253 253 253 253 253
50852-253 253 253 253 253 253 253 253 253 253 253 253
50853-253 253 253 253 253 253 253 253 253 253 253 253
50854-253 253 253 253 253 253 253 253 253 253 253 253
50855-253 253 253 253 253 253 206 206 206 2 2 6
50856- 22 22 22 34 34 34 18 14 6 22 22 22
50857- 26 26 26 18 18 18 6 6 6 2 2 6
50858- 2 2 6 82 82 82 54 54 54 18 18 18
50859- 6 6 6 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 0 0 0 0 0 0
50862- 0 0 0 0 0 0 0 0 0 0 0 0
50863- 0 0 0 0 0 0 0 0 0 0 0 0
50864- 0 0 0 0 0 0 0 0 0 0 0 0
50865- 0 0 0 0 0 0 6 6 6 26 26 26
50866- 62 62 62 106 106 106 74 54 14 185 133 11
50867-210 162 10 121 92 8 6 6 6 62 62 62
50868-238 238 238 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 231 231 231 246 246 246
50871-253 253 253 253 253 253 253 253 253 253 253 253
50872-253 253 253 253 253 253 253 253 253 253 253 253
50873-253 253 253 253 253 253 253 253 253 253 253 253
50874-253 253 253 253 253 253 253 253 253 253 253 253
50875-253 253 253 253 253 253 158 158 158 18 18 18
50876- 14 14 14 2 2 6 2 2 6 2 2 6
50877- 6 6 6 18 18 18 66 66 66 38 38 38
50878- 6 6 6 94 94 94 50 50 50 18 18 18
50879- 6 6 6 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 0 0 0 0 0 0
50882- 0 0 0 0 0 0 0 0 0 0 0 0
50883- 0 0 0 0 0 0 0 0 0 0 0 0
50884- 0 0 0 0 0 0 0 0 0 6 6 6
50885- 10 10 10 10 10 10 18 18 18 38 38 38
50886- 78 78 78 142 134 106 216 158 10 242 186 14
50887-246 190 14 246 190 14 156 118 10 10 10 10
50888- 90 90 90 238 238 238 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 231 231 231 250 250 250
50891-253 253 253 253 253 253 253 253 253 253 253 253
50892-253 253 253 253 253 253 253 253 253 253 253 253
50893-253 253 253 253 253 253 253 253 253 253 253 253
50894-253 253 253 253 253 253 253 253 253 246 230 190
50895-238 204 91 238 204 91 181 142 44 37 26 9
50896- 2 2 6 2 2 6 2 2 6 2 2 6
50897- 2 2 6 2 2 6 38 38 38 46 46 46
50898- 26 26 26 106 106 106 54 54 54 18 18 18
50899- 6 6 6 0 0 0 0 0 0 0 0 0
50900- 0 0 0 0 0 0 0 0 0 0 0 0
50901- 0 0 0 0 0 0 0 0 0 0 0 0
50902- 0 0 0 0 0 0 0 0 0 0 0 0
50903- 0 0 0 0 0 0 0 0 0 0 0 0
50904- 0 0 0 6 6 6 14 14 14 22 22 22
50905- 30 30 30 38 38 38 50 50 50 70 70 70
50906-106 106 106 190 142 34 226 170 11 242 186 14
50907-246 190 14 246 190 14 246 190 14 154 114 10
50908- 6 6 6 74 74 74 226 226 226 253 253 253
50909-253 253 253 253 253 253 253 253 253 253 253 253
50910-253 253 253 253 253 253 231 231 231 250 250 250
50911-253 253 253 253 253 253 253 253 253 253 253 253
50912-253 253 253 253 253 253 253 253 253 253 253 253
50913-253 253 253 253 253 253 253 253 253 253 253 253
50914-253 253 253 253 253 253 253 253 253 228 184 62
50915-241 196 14 241 208 19 232 195 16 38 30 10
50916- 2 2 6 2 2 6 2 2 6 2 2 6
50917- 2 2 6 6 6 6 30 30 30 26 26 26
50918-203 166 17 154 142 90 66 66 66 26 26 26
50919- 6 6 6 0 0 0 0 0 0 0 0 0
50920- 0 0 0 0 0 0 0 0 0 0 0 0
50921- 0 0 0 0 0 0 0 0 0 0 0 0
50922- 0 0 0 0 0 0 0 0 0 0 0 0
50923- 0 0 0 0 0 0 0 0 0 0 0 0
50924- 6 6 6 18 18 18 38 38 38 58 58 58
50925- 78 78 78 86 86 86 101 101 101 123 123 123
50926-175 146 61 210 150 10 234 174 13 246 186 14
50927-246 190 14 246 190 14 246 190 14 238 190 10
50928-102 78 10 2 2 6 46 46 46 198 198 198
50929-253 253 253 253 253 253 253 253 253 253 253 253
50930-253 253 253 253 253 253 234 234 234 242 242 242
50931-253 253 253 253 253 253 253 253 253 253 253 253
50932-253 253 253 253 253 253 253 253 253 253 253 253
50933-253 253 253 253 253 253 253 253 253 253 253 253
50934-253 253 253 253 253 253 253 253 253 224 178 62
50935-242 186 14 241 196 14 210 166 10 22 18 6
50936- 2 2 6 2 2 6 2 2 6 2 2 6
50937- 2 2 6 2 2 6 6 6 6 121 92 8
50938-238 202 15 232 195 16 82 82 82 34 34 34
50939- 10 10 10 0 0 0 0 0 0 0 0 0
50940- 0 0 0 0 0 0 0 0 0 0 0 0
50941- 0 0 0 0 0 0 0 0 0 0 0 0
50942- 0 0 0 0 0 0 0 0 0 0 0 0
50943- 0 0 0 0 0 0 0 0 0 0 0 0
50944- 14 14 14 38 38 38 70 70 70 154 122 46
50945-190 142 34 200 144 11 197 138 11 197 138 11
50946-213 154 11 226 170 11 242 186 14 246 190 14
50947-246 190 14 246 190 14 246 190 14 246 190 14
50948-225 175 15 46 32 6 2 2 6 22 22 22
50949-158 158 158 250 250 250 253 253 253 253 253 253
50950-253 253 253 253 253 253 253 253 253 253 253 253
50951-253 253 253 253 253 253 253 253 253 253 253 253
50952-253 253 253 253 253 253 253 253 253 253 253 253
50953-253 253 253 253 253 253 253 253 253 253 253 253
50954-253 253 253 250 250 250 242 242 242 224 178 62
50955-239 182 13 236 186 11 213 154 11 46 32 6
50956- 2 2 6 2 2 6 2 2 6 2 2 6
50957- 2 2 6 2 2 6 61 42 6 225 175 15
50958-238 190 10 236 186 11 112 100 78 42 42 42
50959- 14 14 14 0 0 0 0 0 0 0 0 0
50960- 0 0 0 0 0 0 0 0 0 0 0 0
50961- 0 0 0 0 0 0 0 0 0 0 0 0
50962- 0 0 0 0 0 0 0 0 0 0 0 0
50963- 0 0 0 0 0 0 0 0 0 6 6 6
50964- 22 22 22 54 54 54 154 122 46 213 154 11
50965-226 170 11 230 174 11 226 170 11 226 170 11
50966-236 178 12 242 186 14 246 190 14 246 190 14
50967-246 190 14 246 190 14 246 190 14 246 190 14
50968-241 196 14 184 144 12 10 10 10 2 2 6
50969- 6 6 6 116 116 116 242 242 242 253 253 253
50970-253 253 253 253 253 253 253 253 253 253 253 253
50971-253 253 253 253 253 253 253 253 253 253 253 253
50972-253 253 253 253 253 253 253 253 253 253 253 253
50973-253 253 253 253 253 253 253 253 253 253 253 253
50974-253 253 253 231 231 231 198 198 198 214 170 54
50975-236 178 12 236 178 12 210 150 10 137 92 6
50976- 18 14 6 2 2 6 2 2 6 2 2 6
50977- 6 6 6 70 47 6 200 144 11 236 178 12
50978-239 182 13 239 182 13 124 112 88 58 58 58
50979- 22 22 22 6 6 6 0 0 0 0 0 0
50980- 0 0 0 0 0 0 0 0 0 0 0 0
50981- 0 0 0 0 0 0 0 0 0 0 0 0
50982- 0 0 0 0 0 0 0 0 0 0 0 0
50983- 0 0 0 0 0 0 0 0 0 10 10 10
50984- 30 30 30 70 70 70 180 133 36 226 170 11
50985-239 182 13 242 186 14 242 186 14 246 186 14
50986-246 190 14 246 190 14 246 190 14 246 190 14
50987-246 190 14 246 190 14 246 190 14 246 190 14
50988-246 190 14 232 195 16 98 70 6 2 2 6
50989- 2 2 6 2 2 6 66 66 66 221 221 221
50990-253 253 253 253 253 253 253 253 253 253 253 253
50991-253 253 253 253 253 253 253 253 253 253 253 253
50992-253 253 253 253 253 253 253 253 253 253 253 253
50993-253 253 253 253 253 253 253 253 253 253 253 253
50994-253 253 253 206 206 206 198 198 198 214 166 58
50995-230 174 11 230 174 11 216 158 10 192 133 9
50996-163 110 8 116 81 8 102 78 10 116 81 8
50997-167 114 7 197 138 11 226 170 11 239 182 13
50998-242 186 14 242 186 14 162 146 94 78 78 78
50999- 34 34 34 14 14 14 6 6 6 0 0 0
51000- 0 0 0 0 0 0 0 0 0 0 0 0
51001- 0 0 0 0 0 0 0 0 0 0 0 0
51002- 0 0 0 0 0 0 0 0 0 0 0 0
51003- 0 0 0 0 0 0 0 0 0 6 6 6
51004- 30 30 30 78 78 78 190 142 34 226 170 11
51005-239 182 13 246 190 14 246 190 14 246 190 14
51006-246 190 14 246 190 14 246 190 14 246 190 14
51007-246 190 14 246 190 14 246 190 14 246 190 14
51008-246 190 14 241 196 14 203 166 17 22 18 6
51009- 2 2 6 2 2 6 2 2 6 38 38 38
51010-218 218 218 253 253 253 253 253 253 253 253 253
51011-253 253 253 253 253 253 253 253 253 253 253 253
51012-253 253 253 253 253 253 253 253 253 253 253 253
51013-253 253 253 253 253 253 253 253 253 253 253 253
51014-250 250 250 206 206 206 198 198 198 202 162 69
51015-226 170 11 236 178 12 224 166 10 210 150 10
51016-200 144 11 197 138 11 192 133 9 197 138 11
51017-210 150 10 226 170 11 242 186 14 246 190 14
51018-246 190 14 246 186 14 225 175 15 124 112 88
51019- 62 62 62 30 30 30 14 14 14 6 6 6
51020- 0 0 0 0 0 0 0 0 0 0 0 0
51021- 0 0 0 0 0 0 0 0 0 0 0 0
51022- 0 0 0 0 0 0 0 0 0 0 0 0
51023- 0 0 0 0 0 0 0 0 0 10 10 10
51024- 30 30 30 78 78 78 174 135 50 224 166 10
51025-239 182 13 246 190 14 246 190 14 246 190 14
51026-246 190 14 246 190 14 246 190 14 246 190 14
51027-246 190 14 246 190 14 246 190 14 246 190 14
51028-246 190 14 246 190 14 241 196 14 139 102 15
51029- 2 2 6 2 2 6 2 2 6 2 2 6
51030- 78 78 78 250 250 250 253 253 253 253 253 253
51031-253 253 253 253 253 253 253 253 253 253 253 253
51032-253 253 253 253 253 253 253 253 253 253 253 253
51033-253 253 253 253 253 253 253 253 253 253 253 253
51034-250 250 250 214 214 214 198 198 198 190 150 46
51035-219 162 10 236 178 12 234 174 13 224 166 10
51036-216 158 10 213 154 11 213 154 11 216 158 10
51037-226 170 11 239 182 13 246 190 14 246 190 14
51038-246 190 14 246 190 14 242 186 14 206 162 42
51039-101 101 101 58 58 58 30 30 30 14 14 14
51040- 6 6 6 0 0 0 0 0 0 0 0 0
51041- 0 0 0 0 0 0 0 0 0 0 0 0
51042- 0 0 0 0 0 0 0 0 0 0 0 0
51043- 0 0 0 0 0 0 0 0 0 10 10 10
51044- 30 30 30 74 74 74 174 135 50 216 158 10
51045-236 178 12 246 190 14 246 190 14 246 190 14
51046-246 190 14 246 190 14 246 190 14 246 190 14
51047-246 190 14 246 190 14 246 190 14 246 190 14
51048-246 190 14 246 190 14 241 196 14 226 184 13
51049- 61 42 6 2 2 6 2 2 6 2 2 6
51050- 22 22 22 238 238 238 253 253 253 253 253 253
51051-253 253 253 253 253 253 253 253 253 253 253 253
51052-253 253 253 253 253 253 253 253 253 253 253 253
51053-253 253 253 253 253 253 253 253 253 253 253 253
51054-253 253 253 226 226 226 187 187 187 180 133 36
51055-216 158 10 236 178 12 239 182 13 236 178 12
51056-230 174 11 226 170 11 226 170 11 230 174 11
51057-236 178 12 242 186 14 246 190 14 246 190 14
51058-246 190 14 246 190 14 246 186 14 239 182 13
51059-206 162 42 106 106 106 66 66 66 34 34 34
51060- 14 14 14 6 6 6 0 0 0 0 0 0
51061- 0 0 0 0 0 0 0 0 0 0 0 0
51062- 0 0 0 0 0 0 0 0 0 0 0 0
51063- 0 0 0 0 0 0 0 0 0 6 6 6
51064- 26 26 26 70 70 70 163 133 67 213 154 11
51065-236 178 12 246 190 14 246 190 14 246 190 14
51066-246 190 14 246 190 14 246 190 14 246 190 14
51067-246 190 14 246 190 14 246 190 14 246 190 14
51068-246 190 14 246 190 14 246 190 14 241 196 14
51069-190 146 13 18 14 6 2 2 6 2 2 6
51070- 46 46 46 246 246 246 253 253 253 253 253 253
51071-253 253 253 253 253 253 253 253 253 253 253 253
51072-253 253 253 253 253 253 253 253 253 253 253 253
51073-253 253 253 253 253 253 253 253 253 253 253 253
51074-253 253 253 221 221 221 86 86 86 156 107 11
51075-216 158 10 236 178 12 242 186 14 246 186 14
51076-242 186 14 239 182 13 239 182 13 242 186 14
51077-242 186 14 246 186 14 246 190 14 246 190 14
51078-246 190 14 246 190 14 246 190 14 246 190 14
51079-242 186 14 225 175 15 142 122 72 66 66 66
51080- 30 30 30 10 10 10 0 0 0 0 0 0
51081- 0 0 0 0 0 0 0 0 0 0 0 0
51082- 0 0 0 0 0 0 0 0 0 0 0 0
51083- 0 0 0 0 0 0 0 0 0 6 6 6
51084- 26 26 26 70 70 70 163 133 67 210 150 10
51085-236 178 12 246 190 14 246 190 14 246 190 14
51086-246 190 14 246 190 14 246 190 14 246 190 14
51087-246 190 14 246 190 14 246 190 14 246 190 14
51088-246 190 14 246 190 14 246 190 14 246 190 14
51089-232 195 16 121 92 8 34 34 34 106 106 106
51090-221 221 221 253 253 253 253 253 253 253 253 253
51091-253 253 253 253 253 253 253 253 253 253 253 253
51092-253 253 253 253 253 253 253 253 253 253 253 253
51093-253 253 253 253 253 253 253 253 253 253 253 253
51094-242 242 242 82 82 82 18 14 6 163 110 8
51095-216 158 10 236 178 12 242 186 14 246 190 14
51096-246 190 14 246 190 14 246 190 14 246 190 14
51097-246 190 14 246 190 14 246 190 14 246 190 14
51098-246 190 14 246 190 14 246 190 14 246 190 14
51099-246 190 14 246 190 14 242 186 14 163 133 67
51100- 46 46 46 18 18 18 6 6 6 0 0 0
51101- 0 0 0 0 0 0 0 0 0 0 0 0
51102- 0 0 0 0 0 0 0 0 0 0 0 0
51103- 0 0 0 0 0 0 0 0 0 10 10 10
51104- 30 30 30 78 78 78 163 133 67 210 150 10
51105-236 178 12 246 186 14 246 190 14 246 190 14
51106-246 190 14 246 190 14 246 190 14 246 190 14
51107-246 190 14 246 190 14 246 190 14 246 190 14
51108-246 190 14 246 190 14 246 190 14 246 190 14
51109-241 196 14 215 174 15 190 178 144 253 253 253
51110-253 253 253 253 253 253 253 253 253 253 253 253
51111-253 253 253 253 253 253 253 253 253 253 253 253
51112-253 253 253 253 253 253 253 253 253 253 253 253
51113-253 253 253 253 253 253 253 253 253 218 218 218
51114- 58 58 58 2 2 6 22 18 6 167 114 7
51115-216 158 10 236 178 12 246 186 14 246 190 14
51116-246 190 14 246 190 14 246 190 14 246 190 14
51117-246 190 14 246 190 14 246 190 14 246 190 14
51118-246 190 14 246 190 14 246 190 14 246 190 14
51119-246 190 14 246 186 14 242 186 14 190 150 46
51120- 54 54 54 22 22 22 6 6 6 0 0 0
51121- 0 0 0 0 0 0 0 0 0 0 0 0
51122- 0 0 0 0 0 0 0 0 0 0 0 0
51123- 0 0 0 0 0 0 0 0 0 14 14 14
51124- 38 38 38 86 86 86 180 133 36 213 154 11
51125-236 178 12 246 186 14 246 190 14 246 190 14
51126-246 190 14 246 190 14 246 190 14 246 190 14
51127-246 190 14 246 190 14 246 190 14 246 190 14
51128-246 190 14 246 190 14 246 190 14 246 190 14
51129-246 190 14 232 195 16 190 146 13 214 214 214
51130-253 253 253 253 253 253 253 253 253 253 253 253
51131-253 253 253 253 253 253 253 253 253 253 253 253
51132-253 253 253 253 253 253 253 253 253 253 253 253
51133-253 253 253 250 250 250 170 170 170 26 26 26
51134- 2 2 6 2 2 6 37 26 9 163 110 8
51135-219 162 10 239 182 13 246 186 14 246 190 14
51136-246 190 14 246 190 14 246 190 14 246 190 14
51137-246 190 14 246 190 14 246 190 14 246 190 14
51138-246 190 14 246 190 14 246 190 14 246 190 14
51139-246 186 14 236 178 12 224 166 10 142 122 72
51140- 46 46 46 18 18 18 6 6 6 0 0 0
51141- 0 0 0 0 0 0 0 0 0 0 0 0
51142- 0 0 0 0 0 0 0 0 0 0 0 0
51143- 0 0 0 0 0 0 6 6 6 18 18 18
51144- 50 50 50 109 106 95 192 133 9 224 166 10
51145-242 186 14 246 190 14 246 190 14 246 190 14
51146-246 190 14 246 190 14 246 190 14 246 190 14
51147-246 190 14 246 190 14 246 190 14 246 190 14
51148-246 190 14 246 190 14 246 190 14 246 190 14
51149-242 186 14 226 184 13 210 162 10 142 110 46
51150-226 226 226 253 253 253 253 253 253 253 253 253
51151-253 253 253 253 253 253 253 253 253 253 253 253
51152-253 253 253 253 253 253 253 253 253 253 253 253
51153-198 198 198 66 66 66 2 2 6 2 2 6
51154- 2 2 6 2 2 6 50 34 6 156 107 11
51155-219 162 10 239 182 13 246 186 14 246 190 14
51156-246 190 14 246 190 14 246 190 14 246 190 14
51157-246 190 14 246 190 14 246 190 14 246 190 14
51158-246 190 14 246 190 14 246 190 14 242 186 14
51159-234 174 13 213 154 11 154 122 46 66 66 66
51160- 30 30 30 10 10 10 0 0 0 0 0 0
51161- 0 0 0 0 0 0 0 0 0 0 0 0
51162- 0 0 0 0 0 0 0 0 0 0 0 0
51163- 0 0 0 0 0 0 6 6 6 22 22 22
51164- 58 58 58 154 121 60 206 145 10 234 174 13
51165-242 186 14 246 186 14 246 190 14 246 190 14
51166-246 190 14 246 190 14 246 190 14 246 190 14
51167-246 190 14 246 190 14 246 190 14 246 190 14
51168-246 190 14 246 190 14 246 190 14 246 190 14
51169-246 186 14 236 178 12 210 162 10 163 110 8
51170- 61 42 6 138 138 138 218 218 218 250 250 250
51171-253 253 253 253 253 253 253 253 253 250 250 250
51172-242 242 242 210 210 210 144 144 144 66 66 66
51173- 6 6 6 2 2 6 2 2 6 2 2 6
51174- 2 2 6 2 2 6 61 42 6 163 110 8
51175-216 158 10 236 178 12 246 190 14 246 190 14
51176-246 190 14 246 190 14 246 190 14 246 190 14
51177-246 190 14 246 190 14 246 190 14 246 190 14
51178-246 190 14 239 182 13 230 174 11 216 158 10
51179-190 142 34 124 112 88 70 70 70 38 38 38
51180- 18 18 18 6 6 6 0 0 0 0 0 0
51181- 0 0 0 0 0 0 0 0 0 0 0 0
51182- 0 0 0 0 0 0 0 0 0 0 0 0
51183- 0 0 0 0 0 0 6 6 6 22 22 22
51184- 62 62 62 168 124 44 206 145 10 224 166 10
51185-236 178 12 239 182 13 242 186 14 242 186 14
51186-246 186 14 246 190 14 246 190 14 246 190 14
51187-246 190 14 246 190 14 246 190 14 246 190 14
51188-246 190 14 246 190 14 246 190 14 246 190 14
51189-246 190 14 236 178 12 216 158 10 175 118 6
51190- 80 54 7 2 2 6 6 6 6 30 30 30
51191- 54 54 54 62 62 62 50 50 50 38 38 38
51192- 14 14 14 2 2 6 2 2 6 2 2 6
51193- 2 2 6 2 2 6 2 2 6 2 2 6
51194- 2 2 6 6 6 6 80 54 7 167 114 7
51195-213 154 11 236 178 12 246 190 14 246 190 14
51196-246 190 14 246 190 14 246 190 14 246 190 14
51197-246 190 14 242 186 14 239 182 13 239 182 13
51198-230 174 11 210 150 10 174 135 50 124 112 88
51199- 82 82 82 54 54 54 34 34 34 18 18 18
51200- 6 6 6 0 0 0 0 0 0 0 0 0
51201- 0 0 0 0 0 0 0 0 0 0 0 0
51202- 0 0 0 0 0 0 0 0 0 0 0 0
51203- 0 0 0 0 0 0 6 6 6 18 18 18
51204- 50 50 50 158 118 36 192 133 9 200 144 11
51205-216 158 10 219 162 10 224 166 10 226 170 11
51206-230 174 11 236 178 12 239 182 13 239 182 13
51207-242 186 14 246 186 14 246 190 14 246 190 14
51208-246 190 14 246 190 14 246 190 14 246 190 14
51209-246 186 14 230 174 11 210 150 10 163 110 8
51210-104 69 6 10 10 10 2 2 6 2 2 6
51211- 2 2 6 2 2 6 2 2 6 2 2 6
51212- 2 2 6 2 2 6 2 2 6 2 2 6
51213- 2 2 6 2 2 6 2 2 6 2 2 6
51214- 2 2 6 6 6 6 91 60 6 167 114 7
51215-206 145 10 230 174 11 242 186 14 246 190 14
51216-246 190 14 246 190 14 246 186 14 242 186 14
51217-239 182 13 230 174 11 224 166 10 213 154 11
51218-180 133 36 124 112 88 86 86 86 58 58 58
51219- 38 38 38 22 22 22 10 10 10 6 6 6
51220- 0 0 0 0 0 0 0 0 0 0 0 0
51221- 0 0 0 0 0 0 0 0 0 0 0 0
51222- 0 0 0 0 0 0 0 0 0 0 0 0
51223- 0 0 0 0 0 0 0 0 0 14 14 14
51224- 34 34 34 70 70 70 138 110 50 158 118 36
51225-167 114 7 180 123 7 192 133 9 197 138 11
51226-200 144 11 206 145 10 213 154 11 219 162 10
51227-224 166 10 230 174 11 239 182 13 242 186 14
51228-246 186 14 246 186 14 246 186 14 246 186 14
51229-239 182 13 216 158 10 185 133 11 152 99 6
51230-104 69 6 18 14 6 2 2 6 2 2 6
51231- 2 2 6 2 2 6 2 2 6 2 2 6
51232- 2 2 6 2 2 6 2 2 6 2 2 6
51233- 2 2 6 2 2 6 2 2 6 2 2 6
51234- 2 2 6 6 6 6 80 54 7 152 99 6
51235-192 133 9 219 162 10 236 178 12 239 182 13
51236-246 186 14 242 186 14 239 182 13 236 178 12
51237-224 166 10 206 145 10 192 133 9 154 121 60
51238- 94 94 94 62 62 62 42 42 42 22 22 22
51239- 14 14 14 6 6 6 0 0 0 0 0 0
51240- 0 0 0 0 0 0 0 0 0 0 0 0
51241- 0 0 0 0 0 0 0 0 0 0 0 0
51242- 0 0 0 0 0 0 0 0 0 0 0 0
51243- 0 0 0 0 0 0 0 0 0 6 6 6
51244- 18 18 18 34 34 34 58 58 58 78 78 78
51245-101 98 89 124 112 88 142 110 46 156 107 11
51246-163 110 8 167 114 7 175 118 6 180 123 7
51247-185 133 11 197 138 11 210 150 10 219 162 10
51248-226 170 11 236 178 12 236 178 12 234 174 13
51249-219 162 10 197 138 11 163 110 8 130 83 6
51250- 91 60 6 10 10 10 2 2 6 2 2 6
51251- 18 18 18 38 38 38 38 38 38 38 38 38
51252- 38 38 38 38 38 38 38 38 38 38 38 38
51253- 38 38 38 38 38 38 26 26 26 2 2 6
51254- 2 2 6 6 6 6 70 47 6 137 92 6
51255-175 118 6 200 144 11 219 162 10 230 174 11
51256-234 174 13 230 174 11 219 162 10 210 150 10
51257-192 133 9 163 110 8 124 112 88 82 82 82
51258- 50 50 50 30 30 30 14 14 14 6 6 6
51259- 0 0 0 0 0 0 0 0 0 0 0 0
51260- 0 0 0 0 0 0 0 0 0 0 0 0
51261- 0 0 0 0 0 0 0 0 0 0 0 0
51262- 0 0 0 0 0 0 0 0 0 0 0 0
51263- 0 0 0 0 0 0 0 0 0 0 0 0
51264- 6 6 6 14 14 14 22 22 22 34 34 34
51265- 42 42 42 58 58 58 74 74 74 86 86 86
51266-101 98 89 122 102 70 130 98 46 121 87 25
51267-137 92 6 152 99 6 163 110 8 180 123 7
51268-185 133 11 197 138 11 206 145 10 200 144 11
51269-180 123 7 156 107 11 130 83 6 104 69 6
51270- 50 34 6 54 54 54 110 110 110 101 98 89
51271- 86 86 86 82 82 82 78 78 78 78 78 78
51272- 78 78 78 78 78 78 78 78 78 78 78 78
51273- 78 78 78 82 82 82 86 86 86 94 94 94
51274-106 106 106 101 101 101 86 66 34 124 80 6
51275-156 107 11 180 123 7 192 133 9 200 144 11
51276-206 145 10 200 144 11 192 133 9 175 118 6
51277-139 102 15 109 106 95 70 70 70 42 42 42
51278- 22 22 22 10 10 10 0 0 0 0 0 0
51279- 0 0 0 0 0 0 0 0 0 0 0 0
51280- 0 0 0 0 0 0 0 0 0 0 0 0
51281- 0 0 0 0 0 0 0 0 0 0 0 0
51282- 0 0 0 0 0 0 0 0 0 0 0 0
51283- 0 0 0 0 0 0 0 0 0 0 0 0
51284- 0 0 0 0 0 0 6 6 6 10 10 10
51285- 14 14 14 22 22 22 30 30 30 38 38 38
51286- 50 50 50 62 62 62 74 74 74 90 90 90
51287-101 98 89 112 100 78 121 87 25 124 80 6
51288-137 92 6 152 99 6 152 99 6 152 99 6
51289-138 86 6 124 80 6 98 70 6 86 66 30
51290-101 98 89 82 82 82 58 58 58 46 46 46
51291- 38 38 38 34 34 34 34 34 34 34 34 34
51292- 34 34 34 34 34 34 34 34 34 34 34 34
51293- 34 34 34 34 34 34 38 38 38 42 42 42
51294- 54 54 54 82 82 82 94 86 76 91 60 6
51295-134 86 6 156 107 11 167 114 7 175 118 6
51296-175 118 6 167 114 7 152 99 6 121 87 25
51297-101 98 89 62 62 62 34 34 34 18 18 18
51298- 6 6 6 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 0 0 0 0 0 0
51301- 0 0 0 0 0 0 0 0 0 0 0 0
51302- 0 0 0 0 0 0 0 0 0 0 0 0
51303- 0 0 0 0 0 0 0 0 0 0 0 0
51304- 0 0 0 0 0 0 0 0 0 0 0 0
51305- 0 0 0 6 6 6 6 6 6 10 10 10
51306- 18 18 18 22 22 22 30 30 30 42 42 42
51307- 50 50 50 66 66 66 86 86 86 101 98 89
51308-106 86 58 98 70 6 104 69 6 104 69 6
51309-104 69 6 91 60 6 82 62 34 90 90 90
51310- 62 62 62 38 38 38 22 22 22 14 14 14
51311- 10 10 10 10 10 10 10 10 10 10 10 10
51312- 10 10 10 10 10 10 6 6 6 10 10 10
51313- 10 10 10 10 10 10 10 10 10 14 14 14
51314- 22 22 22 42 42 42 70 70 70 89 81 66
51315- 80 54 7 104 69 6 124 80 6 137 92 6
51316-134 86 6 116 81 8 100 82 52 86 86 86
51317- 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0 0 0 0
51322- 0 0 0 0 0 0 0 0 0 0 0 0
51323- 0 0 0 0 0 0 0 0 0 0 0 0
51324- 0 0 0 0 0 0 0 0 0 0 0 0
51325- 0 0 0 0 0 0 0 0 0 0 0 0
51326- 0 0 0 6 6 6 10 10 10 14 14 14
51327- 18 18 18 26 26 26 38 38 38 54 54 54
51328- 70 70 70 86 86 86 94 86 76 89 81 66
51329- 89 81 66 86 86 86 74 74 74 50 50 50
51330- 30 30 30 14 14 14 6 6 6 0 0 0
51331- 0 0 0 0 0 0 0 0 0 0 0 0
51332- 0 0 0 0 0 0 0 0 0 0 0 0
51333- 0 0 0 0 0 0 0 0 0 0 0 0
51334- 6 6 6 18 18 18 34 34 34 58 58 58
51335- 82 82 82 89 81 66 89 81 66 89 81 66
51336- 94 86 66 94 86 76 74 74 74 50 50 50
51337- 26 26 26 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
51343- 0 0 0 0 0 0 0 0 0 0 0 0
51344- 0 0 0 0 0 0 0 0 0 0 0 0
51345- 0 0 0 0 0 0 0 0 0 0 0 0
51346- 0 0 0 0 0 0 0 0 0 0 0 0
51347- 6 6 6 6 6 6 14 14 14 18 18 18
51348- 30 30 30 38 38 38 46 46 46 54 54 54
51349- 50 50 50 42 42 42 30 30 30 18 18 18
51350- 10 10 10 0 0 0 0 0 0 0 0 0
51351- 0 0 0 0 0 0 0 0 0 0 0 0
51352- 0 0 0 0 0 0 0 0 0 0 0 0
51353- 0 0 0 0 0 0 0 0 0 0 0 0
51354- 0 0 0 6 6 6 14 14 14 26 26 26
51355- 38 38 38 50 50 50 58 58 58 58 58 58
51356- 54 54 54 42 42 42 30 30 30 18 18 18
51357- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
51364- 0 0 0 0 0 0 0 0 0 0 0 0
51365- 0 0 0 0 0 0 0 0 0 0 0 0
51366- 0 0 0 0 0 0 0 0 0 0 0 0
51367- 0 0 0 0 0 0 0 0 0 6 6 6
51368- 6 6 6 10 10 10 14 14 14 18 18 18
51369- 18 18 18 14 14 14 10 10 10 6 6 6
51370- 0 0 0 0 0 0 0 0 0 0 0 0
51371- 0 0 0 0 0 0 0 0 0 0 0 0
51372- 0 0 0 0 0 0 0 0 0 0 0 0
51373- 0 0 0 0 0 0 0 0 0 0 0 0
51374- 0 0 0 0 0 0 0 0 0 6 6 6
51375- 14 14 14 18 18 18 22 22 22 22 22 22
51376- 18 18 18 14 14 14 10 10 10 6 6 6
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51395+4 4 4 4 4 4
51396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
51471+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
51476+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51477+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
51485+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
51486+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51489+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
51490+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
51491+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
51492+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51493+4 4 4 4 4 4
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 4 4 4 4 4 4 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
51499+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
51500+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51503+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
51504+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
51505+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
51506+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
51507+4 4 4 4 4 4
51508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51509+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 2 2 2 0 0 0
51512+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
51513+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
51514+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
51515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51516+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51517+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
51518+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
51519+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
51520+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
51521+4 4 4 4 4 4
51522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51523+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
51526+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
51527+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
51528+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
51529+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51530+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
51531+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
51532+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
51533+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
51534+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
51535+4 4 4 4 4 4
51536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51539+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
51540+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
51541+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
51542+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
51543+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51544+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
51545+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
51546+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
51547+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
51548+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
51549+4 4 4 4 4 4
51550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51552+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
51553+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
51554+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
51555+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
51556+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
51557+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
51558+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
51559+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
51560+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
51561+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
51562+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
51563+4 4 4 4 4 4
51564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51566+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
51567+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
51568+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
51569+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
51570+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
51571+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
51572+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
51573+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
51574+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
51575+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
51576+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
51577+4 4 4 4 4 4
51578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51580+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
51581+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
51582+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
51583+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
51584+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
51585+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
51586+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
51587+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
51588+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
51589+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
51590+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51591+4 4 4 4 4 4
51592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51594+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
51595+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
51596+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
51597+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
51598+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
51599+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
51600+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
51601+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
51602+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
51603+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
51604+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
51605+4 4 4 4 4 4
51606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51607+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
51608+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
51609+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
51610+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
51611+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
51612+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
51613+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
51614+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
51615+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
51616+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
51617+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
51618+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
51619+4 4 4 4 4 4
51620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51621+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
51622+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
51623+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
51624+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51625+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
51626+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
51627+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
51628+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
51629+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
51630+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
51631+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
51632+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
51633+0 0 0 4 4 4
51634+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51635+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
51636+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
51637+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
51638+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
51639+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
51640+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
51641+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
51642+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
51643+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
51644+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
51645+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
51646+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
51647+2 0 0 0 0 0
51648+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
51649+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
51650+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
51651+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
51652+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
51653+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
51654+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
51655+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
51656+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
51657+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
51658+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
51659+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
51660+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
51661+37 38 37 0 0 0
51662+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51663+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
51664+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
51665+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
51666+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
51667+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
51668+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
51669+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
51670+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
51671+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
51672+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
51673+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
51674+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
51675+85 115 134 4 0 0
51676+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
51677+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
51678+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
51679+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
51680+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
51681+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
51682+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
51683+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
51684+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
51685+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
51686+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
51687+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
51688+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
51689+60 73 81 4 0 0
51690+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
51691+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
51692+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
51693+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
51694+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
51695+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
51696+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
51697+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
51698+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
51699+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
51700+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
51701+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
51702+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
51703+16 19 21 4 0 0
51704+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
51705+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
51706+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
51707+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
51708+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
51709+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
51710+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
51711+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
51712+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
51713+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
51714+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
51715+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
51716+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
51717+4 0 0 4 3 3
51718+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
51719+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
51720+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
51721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
51722+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
51723+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
51724+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
51725+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
51726+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
51727+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
51728+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
51729+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
51730+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
51731+3 2 2 4 4 4
51732+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
51733+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
51734+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
51735+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51736+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
51737+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
51738+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
51739+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
51740+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
51741+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
51742+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
51743+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
51744+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
51745+4 4 4 4 4 4
51746+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
51747+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
51748+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
51749+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
51750+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
51751+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
51752+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
51753+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
51754+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
51755+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
51756+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
51757+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
51758+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
51759+4 4 4 4 4 4
51760+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
51761+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
51762+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
51763+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
51764+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
51765+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51766+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
51767+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
51768+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
51769+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
51770+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
51771+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
51772+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
51773+5 5 5 5 5 5
51774+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
51775+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
51776+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
51777+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
51778+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
51779+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51780+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
51781+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
51782+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
51783+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
51784+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
51785+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
51786+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51787+5 5 5 4 4 4
51788+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
51789+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
51790+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
51791+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
51792+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51793+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
51794+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
51795+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
51796+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
51797+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
51798+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
51799+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51801+4 4 4 4 4 4
51802+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
51803+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
51804+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
51805+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
51806+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
51807+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51808+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51809+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
51810+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
51811+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
51812+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
51813+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
51814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51815+4 4 4 4 4 4
51816+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
51817+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
51818+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
51819+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
51820+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51821+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
51822+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
51823+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
51824+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
51825+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
51826+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
51827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51829+4 4 4 4 4 4
51830+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51831+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51832+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51833+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51834+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51835+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51836+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51837+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51838+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51839+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51840+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51843+4 4 4 4 4 4
51844+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51845+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51846+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51847+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51848+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51849+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51850+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51851+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51852+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51853+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51854+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51857+4 4 4 4 4 4
51858+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51859+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51860+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51861+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51862+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51863+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51864+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51865+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51866+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51867+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51868+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51871+4 4 4 4 4 4
51872+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51873+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51874+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51875+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51876+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51877+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51878+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51879+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51880+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51881+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51882+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51885+4 4 4 4 4 4
51886+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51887+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51888+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51889+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51890+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51891+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51892+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51893+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51894+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51895+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51896+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51899+4 4 4 4 4 4
51900+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51901+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51902+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51903+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51904+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51905+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51906+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51907+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51908+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51909+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51910+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51913+4 4 4 4 4 4
51914+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51915+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51916+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51917+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51918+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51919+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51920+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51921+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51922+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51923+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51924+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51927+4 4 4 4 4 4
51928+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51929+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51930+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51931+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51932+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51933+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51934+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51935+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51936+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51937+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51938+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51941+4 4 4 4 4 4
51942+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51943+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51944+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51945+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51946+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51947+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51948+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51949+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51950+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51951+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51952+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51955+4 4 4 4 4 4
51956+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51957+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51958+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51959+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51960+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51961+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51962+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51963+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51964+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51965+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51966+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51969+4 4 4 4 4 4
51970+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51971+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51972+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51973+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51974+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51975+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51976+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51977+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51978+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51979+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51980+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51983+4 4 4 4 4 4
51984+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51985+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51986+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51987+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51988+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51989+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51990+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51991+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51992+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51993+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51994+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51997+4 4 4 4 4 4
51998+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51999+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
52000+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
52001+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
52002+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
52003+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
52004+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
52005+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
52006+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52007+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52008+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52011+4 4 4 4 4 4
52012+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
52013+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
52014+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52015+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
52016+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
52017+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
52018+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
52019+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
52020+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
52021+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52022+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52025+4 4 4 4 4 4
52026+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
52027+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
52028+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
52029+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
52030+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
52031+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
52032+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
52033+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
52034+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52035+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52036+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52039+4 4 4 4 4 4
52040+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52041+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
52042+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
52043+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
52044+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
52045+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
52046+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
52047+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
52048+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52049+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52050+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52053+4 4 4 4 4 4
52054+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52055+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
52056+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
52057+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
52058+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
52059+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
52060+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52061+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
52062+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
52063+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52064+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52067+4 4 4 4 4 4
52068+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52069+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
52070+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
52071+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52072+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
52073+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
52074+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
52075+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
52076+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
52077+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52078+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52081+4 4 4 4 4 4
52082+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
52083+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
52084+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
52085+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
52086+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
52087+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
52088+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
52089+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
52090+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
52091+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52092+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52095+4 4 4 4 4 4
52096+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52097+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
52098+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
52099+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
52100+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
52101+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
52102+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
52103+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
52104+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
52105+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52106+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52109+4 4 4 4 4 4
52110+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
52111+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
52112+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
52113+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
52114+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
52115+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
52116+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
52117+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
52118+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
52119+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52120+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52123+4 4 4 4 4 4
52124+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
52125+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
52126+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
52127+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
52128+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
52129+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
52130+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
52131+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
52132+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
52133+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
52134+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52137+4 4 4 4 4 4
52138+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
52139+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
52140+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
52141+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
52142+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
52143+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
52144+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
52145+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
52146+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
52147+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
52148+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52151+4 4 4 4 4 4
52152+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
52153+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52154+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
52155+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
52156+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
52157+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
52158+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
52159+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
52160+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
52161+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
52162+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52165+4 4 4 4 4 4
52166+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
52167+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
52168+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
52169+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
52170+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
52171+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
52172+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52173+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
52174+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
52175+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
52176+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52179+4 4 4 4 4 4
52180+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
52181+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
52182+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
52183+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
52184+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
52185+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
52186+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
52187+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
52188+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
52189+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
52190+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52193+4 4 4 4 4 4
52194+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
52195+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
52196+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52197+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
52198+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
52199+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
52200+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
52201+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
52202+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
52203+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
52204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52207+4 4 4 4 4 4
52208+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52209+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
52210+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
52211+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
52212+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
52213+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
52214+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
52215+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
52216+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
52217+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
52222+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
52223+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
52224+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
52225+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
52226+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
52227+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
52228+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
52229+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
52230+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
52231+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
52232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52233+4 4 4 4 4 4 4 4 4 4 4 4 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
52236+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
52237+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
52238+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
52239+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
52240+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
52241+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
52242+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
52243+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
52244+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
52245+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52247+4 4 4 4 4 4 4 4 4 4 4 4 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
52250+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
52251+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52252+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
52253+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
52254+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
52255+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
52256+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
52257+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
52258+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
52259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52261+4 4 4 4 4 4 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
52264+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
52265+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
52266+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
52267+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
52268+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
52269+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
52270+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
52271+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
52272+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
52273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
52278+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
52279+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
52280+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
52281+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
52282+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
52283+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
52284+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
52285+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
52286+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52288+4 4 4 4 4 4 4 4 4 4 4 4 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
52292+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
52293+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
52294+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52295+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
52296+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
52297+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
52298+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
52299+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
52300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52302+4 4 4 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
52306+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52307+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
52308+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
52309+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
52310+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
52311+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
52312+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
52313+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
52314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
52320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52321+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
52322+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52323+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
52324+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
52325+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
52326+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
52327+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
52328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52329+4 4 4 4 4 4 4 4 4 4 4 4 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
52334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52335+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
52336+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
52337+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
52338+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
52339+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
52340+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
52341+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
52342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52343+4 4 4 4 4 4 4 4 4 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
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 4 4 4 5 5 5 5 5 5 5 5 5
52350+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
52351+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52352+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
52353+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
52354+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
52355+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52357+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
52364+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52365+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
52366+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
52367+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
52368+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
52369+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
52370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52371+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
52378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
52379+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52380+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
52381+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
52382+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
52383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52385+4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
52394+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
52395+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
52396+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
52397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
52408+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
52409+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
52410+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
52411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
52422+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
52423+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
52424+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
52425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5
52436+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
52437+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
52438+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
52439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
52451+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
52452+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
52453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52454+4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
52465+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
52466+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52468+4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6
52479+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
52480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52482+4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3
52493+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
52494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
52502diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
52503index fe92eed..106e085 100644
52504--- a/drivers/video/mb862xx/mb862xxfb_accel.c
52505+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
52506@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52507 struct mb862xxfb_par *par = info->par;
52508
52509 if (info->var.bits_per_pixel == 32) {
52510- info->fbops->fb_fillrect = cfb_fillrect;
52511- info->fbops->fb_copyarea = cfb_copyarea;
52512- info->fbops->fb_imageblit = cfb_imageblit;
52513+ pax_open_kernel();
52514+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52515+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52516+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52517+ pax_close_kernel();
52518 } else {
52519 outreg(disp, GC_L0EM, 3);
52520- info->fbops->fb_fillrect = mb86290fb_fillrect;
52521- info->fbops->fb_copyarea = mb86290fb_copyarea;
52522- info->fbops->fb_imageblit = mb86290fb_imageblit;
52523+ pax_open_kernel();
52524+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52525+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52526+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52527+ pax_close_kernel();
52528 }
52529 outreg(draw, GDC_REG_DRAW_BASE, 0);
52530 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52531diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
52532index ff22871..b129bed 100644
52533--- a/drivers/video/nvidia/nvidia.c
52534+++ b/drivers/video/nvidia/nvidia.c
52535@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52536 info->fix.line_length = (info->var.xres_virtual *
52537 info->var.bits_per_pixel) >> 3;
52538 if (info->var.accel_flags) {
52539- info->fbops->fb_imageblit = nvidiafb_imageblit;
52540- info->fbops->fb_fillrect = nvidiafb_fillrect;
52541- info->fbops->fb_copyarea = nvidiafb_copyarea;
52542- info->fbops->fb_sync = nvidiafb_sync;
52543+ pax_open_kernel();
52544+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52545+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52546+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52547+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52548+ pax_close_kernel();
52549 info->pixmap.scan_align = 4;
52550 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52551 info->flags |= FBINFO_READS_FAST;
52552 NVResetGraphics(info);
52553 } else {
52554- info->fbops->fb_imageblit = cfb_imageblit;
52555- info->fbops->fb_fillrect = cfb_fillrect;
52556- info->fbops->fb_copyarea = cfb_copyarea;
52557- info->fbops->fb_sync = NULL;
52558+ pax_open_kernel();
52559+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52560+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52561+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52562+ *(void **)&info->fbops->fb_sync = NULL;
52563+ pax_close_kernel();
52564 info->pixmap.scan_align = 1;
52565 info->flags |= FBINFO_HWACCEL_DISABLED;
52566 info->flags &= ~FBINFO_READS_FAST;
52567@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52568 info->pixmap.size = 8 * 1024;
52569 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52570
52571- if (!hwcur)
52572- info->fbops->fb_cursor = NULL;
52573+ if (!hwcur) {
52574+ pax_open_kernel();
52575+ *(void **)&info->fbops->fb_cursor = NULL;
52576+ pax_close_kernel();
52577+ }
52578
52579 info->var.accel_flags = (!noaccel);
52580
52581diff --git a/drivers/video/output.c b/drivers/video/output.c
52582index 0d6f2cd..6285b97 100644
52583--- a/drivers/video/output.c
52584+++ b/drivers/video/output.c
52585@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
52586 new_dev->props = op;
52587 new_dev->dev.class = &video_output_class;
52588 new_dev->dev.parent = dev;
52589- dev_set_name(&new_dev->dev, name);
52590+ dev_set_name(&new_dev->dev, "%s", name);
52591 dev_set_drvdata(&new_dev->dev, devdata);
52592 ret_code = device_register(&new_dev->dev);
52593 if (ret_code) {
52594diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
52595index 05c2dc3..ea1f391 100644
52596--- a/drivers/video/s1d13xxxfb.c
52597+++ b/drivers/video/s1d13xxxfb.c
52598@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52599
52600 switch(prod_id) {
52601 case S1D13506_PROD_ID: /* activate acceleration */
52602- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52603- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52604+ pax_open_kernel();
52605+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52606+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52607+ pax_close_kernel();
52608 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52609 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52610 break;
52611diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
52612index b2b33fc..f9f4658 100644
52613--- a/drivers/video/smscufx.c
52614+++ b/drivers/video/smscufx.c
52615@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52616 fb_deferred_io_cleanup(info);
52617 kfree(info->fbdefio);
52618 info->fbdefio = NULL;
52619- info->fbops->fb_mmap = ufx_ops_mmap;
52620+ pax_open_kernel();
52621+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52622+ pax_close_kernel();
52623 }
52624
52625 pr_debug("released /dev/fb%d user=%d count=%d",
52626diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
52627index ec03e72..f578436 100644
52628--- a/drivers/video/udlfb.c
52629+++ b/drivers/video/udlfb.c
52630@@ -623,11 +623,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52631 dlfb_urb_completion(urb);
52632
52633 error:
52634- atomic_add(bytes_sent, &dev->bytes_sent);
52635- atomic_add(bytes_identical, &dev->bytes_identical);
52636- atomic_add(width*height*2, &dev->bytes_rendered);
52637+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52638+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52639+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52640 end_cycles = get_cycles();
52641- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52642+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52643 >> 10)), /* Kcycles */
52644 &dev->cpu_kcycles_used);
52645
52646@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
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(bytes_rendered, &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(bytes_rendered, &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@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52663 fb_deferred_io_cleanup(info);
52664 kfree(info->fbdefio);
52665 info->fbdefio = NULL;
52666- info->fbops->fb_mmap = dlfb_ops_mmap;
52667+ pax_open_kernel();
52668+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52669+ pax_close_kernel();
52670 }
52671
52672 pr_warn("released /dev/fb%d user=%d count=%d\n",
52673@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52674 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52675 struct dlfb_data *dev = fb_info->par;
52676 return snprintf(buf, PAGE_SIZE, "%u\n",
52677- atomic_read(&dev->bytes_rendered));
52678+ atomic_read_unchecked(&dev->bytes_rendered));
52679 }
52680
52681 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52682@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52683 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52684 struct dlfb_data *dev = fb_info->par;
52685 return snprintf(buf, PAGE_SIZE, "%u\n",
52686- atomic_read(&dev->bytes_identical));
52687+ atomic_read_unchecked(&dev->bytes_identical));
52688 }
52689
52690 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52691@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52692 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52693 struct dlfb_data *dev = fb_info->par;
52694 return snprintf(buf, PAGE_SIZE, "%u\n",
52695- atomic_read(&dev->bytes_sent));
52696+ atomic_read_unchecked(&dev->bytes_sent));
52697 }
52698
52699 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52700@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52701 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52702 struct dlfb_data *dev = fb_info->par;
52703 return snprintf(buf, PAGE_SIZE, "%u\n",
52704- atomic_read(&dev->cpu_kcycles_used));
52705+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52706 }
52707
52708 static ssize_t edid_show(
52709@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52710 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52711 struct dlfb_data *dev = fb_info->par;
52712
52713- atomic_set(&dev->bytes_rendered, 0);
52714- atomic_set(&dev->bytes_identical, 0);
52715- atomic_set(&dev->bytes_sent, 0);
52716- atomic_set(&dev->cpu_kcycles_used, 0);
52717+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52718+ atomic_set_unchecked(&dev->bytes_identical, 0);
52719+ atomic_set_unchecked(&dev->bytes_sent, 0);
52720+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52721
52722 return count;
52723 }
52724diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
52725index e328a61..1b08ecb 100644
52726--- a/drivers/video/uvesafb.c
52727+++ b/drivers/video/uvesafb.c
52728@@ -19,6 +19,7 @@
52729 #include <linux/io.h>
52730 #include <linux/mutex.h>
52731 #include <linux/slab.h>
52732+#include <linux/moduleloader.h>
52733 #include <video/edid.h>
52734 #include <video/uvesafb.h>
52735 #ifdef CONFIG_X86
52736@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52737 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52738 par->pmi_setpal = par->ypan = 0;
52739 } else {
52740+
52741+#ifdef CONFIG_PAX_KERNEXEC
52742+#ifdef CONFIG_MODULES
52743+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52744+#endif
52745+ if (!par->pmi_code) {
52746+ par->pmi_setpal = par->ypan = 0;
52747+ return 0;
52748+ }
52749+#endif
52750+
52751 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52752 + task->t.regs.edi);
52753+
52754+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52755+ pax_open_kernel();
52756+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52757+ pax_close_kernel();
52758+
52759+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52760+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52761+#else
52762 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52763 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52764+#endif
52765+
52766 printk(KERN_INFO "uvesafb: protected mode interface info at "
52767 "%04x:%04x\n",
52768 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52769@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52770 par->ypan = ypan;
52771
52772 if (par->pmi_setpal || par->ypan) {
52773+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52774 if (__supported_pte_mask & _PAGE_NX) {
52775 par->pmi_setpal = par->ypan = 0;
52776 printk(KERN_WARNING "uvesafb: NX protection is actively."
52777 "We have better not to use the PMI.\n");
52778- } else {
52779+ } else
52780+#endif
52781 uvesafb_vbe_getpmi(task, par);
52782- }
52783 }
52784 #else
52785 /* The protected mode interface is not available on non-x86. */
52786@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52787 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52788
52789 /* Disable blanking if the user requested so. */
52790- if (!blank)
52791- info->fbops->fb_blank = NULL;
52792+ if (!blank) {
52793+ pax_open_kernel();
52794+ *(void **)&info->fbops->fb_blank = NULL;
52795+ pax_close_kernel();
52796+ }
52797
52798 /*
52799 * Find out how much IO memory is required for the mode with
52800@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52801 info->flags = FBINFO_FLAG_DEFAULT |
52802 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52803
52804- if (!par->ypan)
52805- info->fbops->fb_pan_display = NULL;
52806+ if (!par->ypan) {
52807+ pax_open_kernel();
52808+ *(void **)&info->fbops->fb_pan_display = NULL;
52809+ pax_close_kernel();
52810+ }
52811 }
52812
52813 static void uvesafb_init_mtrr(struct fb_info *info)
52814@@ -1836,6 +1866,11 @@ out:
52815 if (par->vbe_modes)
52816 kfree(par->vbe_modes);
52817
52818+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52819+ if (par->pmi_code)
52820+ module_free_exec(NULL, par->pmi_code);
52821+#endif
52822+
52823 framebuffer_release(info);
52824 return err;
52825 }
52826@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
52827 kfree(par->vbe_state_orig);
52828 if (par->vbe_state_saved)
52829 kfree(par->vbe_state_saved);
52830+
52831+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52832+ if (par->pmi_code)
52833+ module_free_exec(NULL, par->pmi_code);
52834+#endif
52835+
52836 }
52837
52838 framebuffer_release(info);
52839diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52840index 501b340..d80aa17 100644
52841--- a/drivers/video/vesafb.c
52842+++ b/drivers/video/vesafb.c
52843@@ -9,6 +9,7 @@
52844 */
52845
52846 #include <linux/module.h>
52847+#include <linux/moduleloader.h>
52848 #include <linux/kernel.h>
52849 #include <linux/errno.h>
52850 #include <linux/string.h>
52851@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
52852 static int vram_total __initdata; /* Set total amount of memory */
52853 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52854 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52855-static void (*pmi_start)(void) __read_mostly;
52856-static void (*pmi_pal) (void) __read_mostly;
52857+static void (*pmi_start)(void) __read_only;
52858+static void (*pmi_pal) (void) __read_only;
52859 static int depth __read_mostly;
52860 static int vga_compat __read_mostly;
52861 /* --------------------------------------------------------------------- */
52862@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
52863 unsigned int size_vmode;
52864 unsigned int size_remap;
52865 unsigned int size_total;
52866+ void *pmi_code = NULL;
52867
52868 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
52869 return -ENODEV;
52870@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
52871 size_remap = size_total;
52872 vesafb_fix.smem_len = size_remap;
52873
52874-#ifndef __i386__
52875- screen_info.vesapm_seg = 0;
52876-#endif
52877-
52878 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52879 printk(KERN_WARNING
52880 "vesafb: cannot reserve video memory at 0x%lx\n",
52881@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
52882 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52883 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52884
52885+#ifdef __i386__
52886+
52887+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52888+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52889+ if (!pmi_code)
52890+#elif !defined(CONFIG_PAX_KERNEXEC)
52891+ if (0)
52892+#endif
52893+
52894+#endif
52895+ screen_info.vesapm_seg = 0;
52896+
52897 if (screen_info.vesapm_seg) {
52898- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52899- screen_info.vesapm_seg,screen_info.vesapm_off);
52900+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52901+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52902 }
52903
52904 if (screen_info.vesapm_seg < 0xc000)
52905@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
52906
52907 if (ypan || pmi_setpal) {
52908 unsigned short *pmi_base;
52909+
52910 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52911- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52912- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52913+
52914+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52915+ pax_open_kernel();
52916+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52917+#else
52918+ pmi_code = pmi_base;
52919+#endif
52920+
52921+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52922+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52923+
52924+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52925+ pmi_start = ktva_ktla(pmi_start);
52926+ pmi_pal = ktva_ktla(pmi_pal);
52927+ pax_close_kernel();
52928+#endif
52929+
52930 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52931 if (pmi_base[3]) {
52932 printk(KERN_INFO "vesafb: pmi: ports = ");
52933@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52934 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52935 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52936
52937- if (!ypan)
52938- info->fbops->fb_pan_display = NULL;
52939+ if (!ypan) {
52940+ pax_open_kernel();
52941+ *(void **)&info->fbops->fb_pan_display = NULL;
52942+ pax_close_kernel();
52943+ }
52944
52945 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52946 err = -ENOMEM;
52947@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52948 info->node, info->fix.id);
52949 return 0;
52950 err:
52951+
52952+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52953+ module_free_exec(NULL, pmi_code);
52954+#endif
52955+
52956 if (info->screen_base)
52957 iounmap(info->screen_base);
52958 framebuffer_release(info);
52959diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52960index 88714ae..16c2e11 100644
52961--- a/drivers/video/via/via_clock.h
52962+++ b/drivers/video/via/via_clock.h
52963@@ -56,7 +56,7 @@ struct via_clock {
52964
52965 void (*set_engine_pll_state)(u8 state);
52966 void (*set_engine_pll)(struct via_pll_config config);
52967-};
52968+} __no_const;
52969
52970
52971 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52972diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52973index fef20db..d28b1ab 100644
52974--- a/drivers/xen/xenfs/xenstored.c
52975+++ b/drivers/xen/xenfs/xenstored.c
52976@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52977 static int xsd_kva_open(struct inode *inode, struct file *file)
52978 {
52979 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52980+#ifdef CONFIG_GRKERNSEC_HIDESYM
52981+ NULL);
52982+#else
52983 xen_store_interface);
52984+#endif
52985+
52986 if (!file->private_data)
52987 return -ENOMEM;
52988 return 0;
52989diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52990index 055562c..fdfb10d 100644
52991--- a/fs/9p/vfs_addr.c
52992+++ b/fs/9p/vfs_addr.c
52993@@ -186,7 +186,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52994
52995 retval = v9fs_file_write_internal(inode,
52996 v9inode->writeback_fid,
52997- (__force const char __user *)buffer,
52998+ (const char __force_user *)buffer,
52999 len, &offset, 0);
53000 if (retval > 0)
53001 retval = 0;
53002diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
53003index d86edc8..40ff2fb 100644
53004--- a/fs/9p/vfs_inode.c
53005+++ b/fs/9p/vfs_inode.c
53006@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53007 void
53008 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53009 {
53010- char *s = nd_get_link(nd);
53011+ const char *s = nd_get_link(nd);
53012
53013 p9_debug(P9_DEBUG_VFS, " %s %s\n",
53014 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
53015diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
53016index 370b24c..ff0be7b 100644
53017--- a/fs/Kconfig.binfmt
53018+++ b/fs/Kconfig.binfmt
53019@@ -103,7 +103,7 @@ config HAVE_AOUT
53020
53021 config BINFMT_AOUT
53022 tristate "Kernel support for a.out and ECOFF binaries"
53023- depends on HAVE_AOUT
53024+ depends on HAVE_AOUT && BROKEN
53025 ---help---
53026 A.out (Assembler.OUTput) is a set of formats for libraries and
53027 executables used in the earliest versions of UNIX. Linux used
53028diff --git a/fs/afs/inode.c b/fs/afs/inode.c
53029index 789bc25..fafaeea 100644
53030--- a/fs/afs/inode.c
53031+++ b/fs/afs/inode.c
53032@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53033 struct afs_vnode *vnode;
53034 struct super_block *sb;
53035 struct inode *inode;
53036- static atomic_t afs_autocell_ino;
53037+ static atomic_unchecked_t afs_autocell_ino;
53038
53039 _enter("{%x:%u},%*.*s,",
53040 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
53041@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
53042 data.fid.unique = 0;
53043 data.fid.vnode = 0;
53044
53045- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
53046+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
53047 afs_iget5_autocell_test, afs_iget5_set,
53048 &data);
53049 if (!inode) {
53050diff --git a/fs/aio.c b/fs/aio.c
53051index 2bbcacf..8614116 100644
53052--- a/fs/aio.c
53053+++ b/fs/aio.c
53054@@ -160,7 +160,7 @@ static int aio_setup_ring(struct kioctx *ctx)
53055 size += sizeof(struct io_event) * nr_events;
53056 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
53057
53058- if (nr_pages < 0)
53059+ if (nr_pages <= 0)
53060 return -EINVAL;
53061
53062 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
53063@@ -950,6 +950,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
53064 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
53065 {
53066 ssize_t ret;
53067+ struct iovec iovstack;
53068
53069 kiocb->ki_nr_segs = kiocb->ki_nbytes;
53070
53071@@ -957,17 +958,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
53072 if (compat)
53073 ret = compat_rw_copy_check_uvector(rw,
53074 (struct compat_iovec __user *)kiocb->ki_buf,
53075- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
53076+ kiocb->ki_nr_segs, 1, &iovstack,
53077 &kiocb->ki_iovec);
53078 else
53079 #endif
53080 ret = rw_copy_check_uvector(rw,
53081 (struct iovec __user *)kiocb->ki_buf,
53082- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
53083+ kiocb->ki_nr_segs, 1, &iovstack,
53084 &kiocb->ki_iovec);
53085 if (ret < 0)
53086 return ret;
53087
53088+ if (kiocb->ki_iovec == &iovstack) {
53089+ kiocb->ki_inline_vec = iovstack;
53090+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
53091+ }
53092+
53093 /* ki_nbytes now reflect bytes instead of segs */
53094 kiocb->ki_nbytes = ret;
53095 return 0;
53096diff --git a/fs/attr.c b/fs/attr.c
53097index 1449adb..a2038c2 100644
53098--- a/fs/attr.c
53099+++ b/fs/attr.c
53100@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
53101 unsigned long limit;
53102
53103 limit = rlimit(RLIMIT_FSIZE);
53104+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
53105 if (limit != RLIM_INFINITY && offset > limit)
53106 goto out_sig;
53107 if (offset > inode->i_sb->s_maxbytes)
53108diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
53109index 3db70da..7aeec5b 100644
53110--- a/fs/autofs4/waitq.c
53111+++ b/fs/autofs4/waitq.c
53112@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
53113 {
53114 unsigned long sigpipe, flags;
53115 mm_segment_t fs;
53116- const char *data = (const char *)addr;
53117+ const char __user *data = (const char __force_user *)addr;
53118 ssize_t wr = 0;
53119
53120 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
53121@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
53122 return 1;
53123 }
53124
53125+#ifdef CONFIG_GRKERNSEC_HIDESYM
53126+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
53127+#endif
53128+
53129 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53130 enum autofs_notify notify)
53131 {
53132@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
53133
53134 /* If this is a direct mount request create a dummy name */
53135 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
53136+#ifdef CONFIG_GRKERNSEC_HIDESYM
53137+ /* this name does get written to userland via autofs4_write() */
53138+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
53139+#else
53140 qstr.len = sprintf(name, "%p", dentry);
53141+#endif
53142 else {
53143 qstr.len = autofs4_getpath(sbi, dentry, &name);
53144 if (!qstr.len) {
53145diff --git a/fs/befs/endian.h b/fs/befs/endian.h
53146index 2722387..c8dd2a7 100644
53147--- a/fs/befs/endian.h
53148+++ b/fs/befs/endian.h
53149@@ -11,7 +11,7 @@
53150
53151 #include <asm/byteorder.h>
53152
53153-static inline u64
53154+static inline u64 __intentional_overflow(-1)
53155 fs64_to_cpu(const struct super_block *sb, fs64 n)
53156 {
53157 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53158@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
53159 return (__force fs64)cpu_to_be64(n);
53160 }
53161
53162-static inline u32
53163+static inline u32 __intentional_overflow(-1)
53164 fs32_to_cpu(const struct super_block *sb, fs32 n)
53165 {
53166 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
53167diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
53168index f95dddc..b1e2c1c 100644
53169--- a/fs/befs/linuxvfs.c
53170+++ b/fs/befs/linuxvfs.c
53171@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53172 {
53173 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
53174 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
53175- char *link = nd_get_link(nd);
53176+ const char *link = nd_get_link(nd);
53177 if (!IS_ERR(link))
53178 kfree(link);
53179 }
53180diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
53181index bce8769..7fc7544 100644
53182--- a/fs/binfmt_aout.c
53183+++ b/fs/binfmt_aout.c
53184@@ -16,6 +16,7 @@
53185 #include <linux/string.h>
53186 #include <linux/fs.h>
53187 #include <linux/file.h>
53188+#include <linux/security.h>
53189 #include <linux/stat.h>
53190 #include <linux/fcntl.h>
53191 #include <linux/ptrace.h>
53192@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
53193 #endif
53194 # define START_STACK(u) ((void __user *)u.start_stack)
53195
53196+ memset(&dump, 0, sizeof(dump));
53197+
53198 fs = get_fs();
53199 set_fs(KERNEL_DS);
53200 has_dumped = 1;
53201@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
53202
53203 /* If the size of the dump file exceeds the rlimit, then see what would happen
53204 if we wrote the stack, but not the data area. */
53205+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
53206 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
53207 dump.u_dsize = 0;
53208
53209 /* Make sure we have enough room to write the stack and data areas. */
53210+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
53211 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
53212 dump.u_ssize = 0;
53213
53214@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
53215 rlim = rlimit(RLIMIT_DATA);
53216 if (rlim >= RLIM_INFINITY)
53217 rlim = ~0;
53218+
53219+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
53220 if (ex.a_data + ex.a_bss > rlim)
53221 return -ENOMEM;
53222
53223@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
53224
53225 install_exec_creds(bprm);
53226
53227+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53228+ current->mm->pax_flags = 0UL;
53229+#endif
53230+
53231+#ifdef CONFIG_PAX_PAGEEXEC
53232+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
53233+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
53234+
53235+#ifdef CONFIG_PAX_EMUTRAMP
53236+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
53237+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
53238+#endif
53239+
53240+#ifdef CONFIG_PAX_MPROTECT
53241+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
53242+ current->mm->pax_flags |= MF_PAX_MPROTECT;
53243+#endif
53244+
53245+ }
53246+#endif
53247+
53248 if (N_MAGIC(ex) == OMAGIC) {
53249 unsigned long text_addr, map_size;
53250 loff_t pos;
53251@@ -324,7 +352,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
53252 }
53253
53254 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
53255- PROT_READ | PROT_WRITE | PROT_EXEC,
53256+ PROT_READ | PROT_WRITE,
53257 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
53258 fd_offset + ex.a_text);
53259 if (error != N_DATADDR(ex)) {
53260diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
53261index f8a0b0e..6f036ed 100644
53262--- a/fs/binfmt_elf.c
53263+++ b/fs/binfmt_elf.c
53264@@ -34,6 +34,7 @@
53265 #include <linux/utsname.h>
53266 #include <linux/coredump.h>
53267 #include <linux/sched.h>
53268+#include <linux/xattr.h>
53269 #include <asm/uaccess.h>
53270 #include <asm/param.h>
53271 #include <asm/page.h>
53272@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
53273 #define elf_core_dump NULL
53274 #endif
53275
53276+#ifdef CONFIG_PAX_MPROTECT
53277+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
53278+#endif
53279+
53280+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53281+static void elf_handle_mmap(struct file *file);
53282+#endif
53283+
53284 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
53285 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
53286 #else
53287@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
53288 .load_binary = load_elf_binary,
53289 .load_shlib = load_elf_library,
53290 .core_dump = elf_core_dump,
53291+
53292+#ifdef CONFIG_PAX_MPROTECT
53293+ .handle_mprotect= elf_handle_mprotect,
53294+#endif
53295+
53296+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53297+ .handle_mmap = elf_handle_mmap,
53298+#endif
53299+
53300 .min_coredump = ELF_EXEC_PAGESIZE,
53301 };
53302
53303@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
53304
53305 static int set_brk(unsigned long start, unsigned long end)
53306 {
53307+ unsigned long e = end;
53308+
53309 start = ELF_PAGEALIGN(start);
53310 end = ELF_PAGEALIGN(end);
53311 if (end > start) {
53312@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
53313 if (BAD_ADDR(addr))
53314 return addr;
53315 }
53316- current->mm->start_brk = current->mm->brk = end;
53317+ current->mm->start_brk = current->mm->brk = e;
53318 return 0;
53319 }
53320
53321@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53322 elf_addr_t __user *u_rand_bytes;
53323 const char *k_platform = ELF_PLATFORM;
53324 const char *k_base_platform = ELF_BASE_PLATFORM;
53325- unsigned char k_rand_bytes[16];
53326+ u32 k_rand_bytes[4];
53327 int items;
53328 elf_addr_t *elf_info;
53329 int ei_index = 0;
53330 const struct cred *cred = current_cred();
53331 struct vm_area_struct *vma;
53332+ unsigned long saved_auxv[AT_VECTOR_SIZE];
53333
53334 /*
53335 * In some cases (e.g. Hyper-Threading), we want to avoid L1
53336@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53337 * Generate 16 random bytes for userspace PRNG seeding.
53338 */
53339 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
53340- u_rand_bytes = (elf_addr_t __user *)
53341- STACK_ALLOC(p, sizeof(k_rand_bytes));
53342+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
53343+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
53344+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
53345+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
53346+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
53347+ u_rand_bytes = (elf_addr_t __user *) p;
53348 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
53349 return -EFAULT;
53350
53351@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
53352 return -EFAULT;
53353 current->mm->env_end = p;
53354
53355+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
53356+
53357 /* Put the elf_info on the stack in the right place. */
53358 sp = (elf_addr_t __user *)envp + 1;
53359- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
53360+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
53361 return -EFAULT;
53362 return 0;
53363 }
53364@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
53365 an ELF header */
53366
53367 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53368- struct file *interpreter, unsigned long *interp_map_addr,
53369- unsigned long no_base)
53370+ struct file *interpreter, unsigned long no_base)
53371 {
53372 struct elf_phdr *elf_phdata;
53373 struct elf_phdr *eppnt;
53374- unsigned long load_addr = 0;
53375+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
53376 int load_addr_set = 0;
53377 unsigned long last_bss = 0, elf_bss = 0;
53378- unsigned long error = ~0UL;
53379+ unsigned long error = -EINVAL;
53380 unsigned long total_size;
53381 int retval, i, size;
53382
53383@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53384 goto out_close;
53385 }
53386
53387+#ifdef CONFIG_PAX_SEGMEXEC
53388+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
53389+ pax_task_size = SEGMEXEC_TASK_SIZE;
53390+#endif
53391+
53392 eppnt = elf_phdata;
53393 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
53394 if (eppnt->p_type == PT_LOAD) {
53395@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53396 map_addr = elf_map(interpreter, load_addr + vaddr,
53397 eppnt, elf_prot, elf_type, total_size);
53398 total_size = 0;
53399- if (!*interp_map_addr)
53400- *interp_map_addr = map_addr;
53401 error = map_addr;
53402 if (BAD_ADDR(map_addr))
53403 goto out_close;
53404@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
53405 k = load_addr + eppnt->p_vaddr;
53406 if (BAD_ADDR(k) ||
53407 eppnt->p_filesz > eppnt->p_memsz ||
53408- eppnt->p_memsz > TASK_SIZE ||
53409- TASK_SIZE - eppnt->p_memsz < k) {
53410+ eppnt->p_memsz > pax_task_size ||
53411+ pax_task_size - eppnt->p_memsz < k) {
53412 error = -ENOMEM;
53413 goto out_close;
53414 }
53415@@ -538,6 +567,315 @@ out:
53416 return error;
53417 }
53418
53419+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53420+#ifdef CONFIG_PAX_SOFTMODE
53421+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
53422+{
53423+ unsigned long pax_flags = 0UL;
53424+
53425+#ifdef CONFIG_PAX_PAGEEXEC
53426+ if (elf_phdata->p_flags & PF_PAGEEXEC)
53427+ pax_flags |= MF_PAX_PAGEEXEC;
53428+#endif
53429+
53430+#ifdef CONFIG_PAX_SEGMEXEC
53431+ if (elf_phdata->p_flags & PF_SEGMEXEC)
53432+ pax_flags |= MF_PAX_SEGMEXEC;
53433+#endif
53434+
53435+#ifdef CONFIG_PAX_EMUTRAMP
53436+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53437+ pax_flags |= MF_PAX_EMUTRAMP;
53438+#endif
53439+
53440+#ifdef CONFIG_PAX_MPROTECT
53441+ if (elf_phdata->p_flags & PF_MPROTECT)
53442+ pax_flags |= MF_PAX_MPROTECT;
53443+#endif
53444+
53445+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53446+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
53447+ pax_flags |= MF_PAX_RANDMMAP;
53448+#endif
53449+
53450+ return pax_flags;
53451+}
53452+#endif
53453+
53454+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
53455+{
53456+ unsigned long pax_flags = 0UL;
53457+
53458+#ifdef CONFIG_PAX_PAGEEXEC
53459+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
53460+ pax_flags |= MF_PAX_PAGEEXEC;
53461+#endif
53462+
53463+#ifdef CONFIG_PAX_SEGMEXEC
53464+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
53465+ pax_flags |= MF_PAX_SEGMEXEC;
53466+#endif
53467+
53468+#ifdef CONFIG_PAX_EMUTRAMP
53469+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
53470+ pax_flags |= MF_PAX_EMUTRAMP;
53471+#endif
53472+
53473+#ifdef CONFIG_PAX_MPROTECT
53474+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
53475+ pax_flags |= MF_PAX_MPROTECT;
53476+#endif
53477+
53478+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53479+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
53480+ pax_flags |= MF_PAX_RANDMMAP;
53481+#endif
53482+
53483+ return pax_flags;
53484+}
53485+#endif
53486+
53487+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53488+#ifdef CONFIG_PAX_SOFTMODE
53489+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
53490+{
53491+ unsigned long pax_flags = 0UL;
53492+
53493+#ifdef CONFIG_PAX_PAGEEXEC
53494+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
53495+ pax_flags |= MF_PAX_PAGEEXEC;
53496+#endif
53497+
53498+#ifdef CONFIG_PAX_SEGMEXEC
53499+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
53500+ pax_flags |= MF_PAX_SEGMEXEC;
53501+#endif
53502+
53503+#ifdef CONFIG_PAX_EMUTRAMP
53504+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53505+ pax_flags |= MF_PAX_EMUTRAMP;
53506+#endif
53507+
53508+#ifdef CONFIG_PAX_MPROTECT
53509+ if (pax_flags_softmode & MF_PAX_MPROTECT)
53510+ pax_flags |= MF_PAX_MPROTECT;
53511+#endif
53512+
53513+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53514+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
53515+ pax_flags |= MF_PAX_RANDMMAP;
53516+#endif
53517+
53518+ return pax_flags;
53519+}
53520+#endif
53521+
53522+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
53523+{
53524+ unsigned long pax_flags = 0UL;
53525+
53526+#ifdef CONFIG_PAX_PAGEEXEC
53527+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
53528+ pax_flags |= MF_PAX_PAGEEXEC;
53529+#endif
53530+
53531+#ifdef CONFIG_PAX_SEGMEXEC
53532+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
53533+ pax_flags |= MF_PAX_SEGMEXEC;
53534+#endif
53535+
53536+#ifdef CONFIG_PAX_EMUTRAMP
53537+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
53538+ pax_flags |= MF_PAX_EMUTRAMP;
53539+#endif
53540+
53541+#ifdef CONFIG_PAX_MPROTECT
53542+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
53543+ pax_flags |= MF_PAX_MPROTECT;
53544+#endif
53545+
53546+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53547+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
53548+ pax_flags |= MF_PAX_RANDMMAP;
53549+#endif
53550+
53551+ return pax_flags;
53552+}
53553+#endif
53554+
53555+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53556+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
53557+{
53558+ unsigned long pax_flags = 0UL;
53559+
53560+#ifdef CONFIG_PAX_EI_PAX
53561+
53562+#ifdef CONFIG_PAX_PAGEEXEC
53563+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
53564+ pax_flags |= MF_PAX_PAGEEXEC;
53565+#endif
53566+
53567+#ifdef CONFIG_PAX_SEGMEXEC
53568+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
53569+ pax_flags |= MF_PAX_SEGMEXEC;
53570+#endif
53571+
53572+#ifdef CONFIG_PAX_EMUTRAMP
53573+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
53574+ pax_flags |= MF_PAX_EMUTRAMP;
53575+#endif
53576+
53577+#ifdef CONFIG_PAX_MPROTECT
53578+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
53579+ pax_flags |= MF_PAX_MPROTECT;
53580+#endif
53581+
53582+#ifdef CONFIG_PAX_ASLR
53583+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
53584+ pax_flags |= MF_PAX_RANDMMAP;
53585+#endif
53586+
53587+#else
53588+
53589+#ifdef CONFIG_PAX_PAGEEXEC
53590+ pax_flags |= MF_PAX_PAGEEXEC;
53591+#endif
53592+
53593+#ifdef CONFIG_PAX_SEGMEXEC
53594+ pax_flags |= MF_PAX_SEGMEXEC;
53595+#endif
53596+
53597+#ifdef CONFIG_PAX_MPROTECT
53598+ pax_flags |= MF_PAX_MPROTECT;
53599+#endif
53600+
53601+#ifdef CONFIG_PAX_RANDMMAP
53602+ if (randomize_va_space)
53603+ pax_flags |= MF_PAX_RANDMMAP;
53604+#endif
53605+
53606+#endif
53607+
53608+ return pax_flags;
53609+}
53610+
53611+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
53612+{
53613+
53614+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53615+ unsigned long i;
53616+
53617+ for (i = 0UL; i < elf_ex->e_phnum; i++)
53618+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
53619+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
53620+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
53621+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
53622+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
53623+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
53624+ return ~0UL;
53625+
53626+#ifdef CONFIG_PAX_SOFTMODE
53627+ if (pax_softmode)
53628+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
53629+ else
53630+#endif
53631+
53632+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
53633+ break;
53634+ }
53635+#endif
53636+
53637+ return ~0UL;
53638+}
53639+
53640+static unsigned long pax_parse_xattr_pax(struct file * const file)
53641+{
53642+
53643+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53644+ ssize_t xattr_size, i;
53645+ unsigned char xattr_value[sizeof("pemrs") - 1];
53646+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
53647+
53648+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
53649+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
53650+ return ~0UL;
53651+
53652+ for (i = 0; i < xattr_size; i++)
53653+ switch (xattr_value[i]) {
53654+ default:
53655+ return ~0UL;
53656+
53657+#define parse_flag(option1, option2, flag) \
53658+ case option1: \
53659+ if (pax_flags_hardmode & MF_PAX_##flag) \
53660+ return ~0UL; \
53661+ pax_flags_hardmode |= MF_PAX_##flag; \
53662+ break; \
53663+ case option2: \
53664+ if (pax_flags_softmode & MF_PAX_##flag) \
53665+ return ~0UL; \
53666+ pax_flags_softmode |= MF_PAX_##flag; \
53667+ break;
53668+
53669+ parse_flag('p', 'P', PAGEEXEC);
53670+ parse_flag('e', 'E', EMUTRAMP);
53671+ parse_flag('m', 'M', MPROTECT);
53672+ parse_flag('r', 'R', RANDMMAP);
53673+ parse_flag('s', 'S', SEGMEXEC);
53674+
53675+#undef parse_flag
53676+ }
53677+
53678+ if (pax_flags_hardmode & pax_flags_softmode)
53679+ return ~0UL;
53680+
53681+#ifdef CONFIG_PAX_SOFTMODE
53682+ if (pax_softmode)
53683+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
53684+ else
53685+#endif
53686+
53687+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
53688+#else
53689+ return ~0UL;
53690+#endif
53691+
53692+}
53693+
53694+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
53695+{
53696+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
53697+
53698+ pax_flags = pax_parse_ei_pax(elf_ex);
53699+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
53700+ xattr_pax_flags = pax_parse_xattr_pax(file);
53701+
53702+ if (pt_pax_flags == ~0UL)
53703+ pt_pax_flags = xattr_pax_flags;
53704+ else if (xattr_pax_flags == ~0UL)
53705+ xattr_pax_flags = pt_pax_flags;
53706+ if (pt_pax_flags != xattr_pax_flags)
53707+ return -EINVAL;
53708+ if (pt_pax_flags != ~0UL)
53709+ pax_flags = pt_pax_flags;
53710+
53711+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
53712+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53713+ if ((__supported_pte_mask & _PAGE_NX))
53714+ pax_flags &= ~MF_PAX_SEGMEXEC;
53715+ else
53716+ pax_flags &= ~MF_PAX_PAGEEXEC;
53717+ }
53718+#endif
53719+
53720+ if (0 > pax_check_flags(&pax_flags))
53721+ return -EINVAL;
53722+
53723+ current->mm->pax_flags = pax_flags;
53724+ return 0;
53725+}
53726+#endif
53727+
53728 /*
53729 * These are the functions used to load ELF style executables and shared
53730 * libraries. There is no binary dependent code anywhere else.
53731@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
53732 {
53733 unsigned int random_variable = 0;
53734
53735+#ifdef CONFIG_PAX_RANDUSTACK
53736+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
53737+ return stack_top - current->mm->delta_stack;
53738+#endif
53739+
53740 if ((current->flags & PF_RANDOMIZE) &&
53741 !(current->personality & ADDR_NO_RANDOMIZE)) {
53742 random_variable = get_random_int() & STACK_RND_MASK;
53743@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
53744 unsigned long load_addr = 0, load_bias = 0;
53745 int load_addr_set = 0;
53746 char * elf_interpreter = NULL;
53747- unsigned long error;
53748+ unsigned long error = 0;
53749 struct elf_phdr *elf_ppnt, *elf_phdata;
53750 unsigned long elf_bss, elf_brk;
53751 int retval, i;
53752@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
53753 unsigned long start_code, end_code, start_data, end_data;
53754 unsigned long reloc_func_desc __maybe_unused = 0;
53755 int executable_stack = EXSTACK_DEFAULT;
53756- unsigned long def_flags = 0;
53757 struct pt_regs *regs = current_pt_regs();
53758 struct {
53759 struct elfhdr elf_ex;
53760 struct elfhdr interp_elf_ex;
53761 } *loc;
53762+ unsigned long pax_task_size = TASK_SIZE;
53763
53764 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
53765 if (!loc) {
53766@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
53767 goto out_free_dentry;
53768
53769 /* OK, This is the point of no return */
53770- current->mm->def_flags = def_flags;
53771+
53772+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53773+ current->mm->pax_flags = 0UL;
53774+#endif
53775+
53776+#ifdef CONFIG_PAX_DLRESOLVE
53777+ current->mm->call_dl_resolve = 0UL;
53778+#endif
53779+
53780+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
53781+ current->mm->call_syscall = 0UL;
53782+#endif
53783+
53784+#ifdef CONFIG_PAX_ASLR
53785+ current->mm->delta_mmap = 0UL;
53786+ current->mm->delta_stack = 0UL;
53787+#endif
53788+
53789+ current->mm->def_flags = 0;
53790+
53791+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53792+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
53793+ send_sig(SIGKILL, current, 0);
53794+ goto out_free_dentry;
53795+ }
53796+#endif
53797+
53798+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53799+ pax_set_initial_flags(bprm);
53800+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
53801+ if (pax_set_initial_flags_func)
53802+ (pax_set_initial_flags_func)(bprm);
53803+#endif
53804+
53805+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53806+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
53807+ current->mm->context.user_cs_limit = PAGE_SIZE;
53808+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
53809+ }
53810+#endif
53811+
53812+#ifdef CONFIG_PAX_SEGMEXEC
53813+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
53814+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
53815+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
53816+ pax_task_size = SEGMEXEC_TASK_SIZE;
53817+ current->mm->def_flags |= VM_NOHUGEPAGE;
53818+ }
53819+#endif
53820+
53821+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
53822+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53823+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
53824+ put_cpu();
53825+ }
53826+#endif
53827
53828 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
53829 may depend on the personality. */
53830 SET_PERSONALITY(loc->elf_ex);
53831+
53832+#ifdef CONFIG_PAX_ASLR
53833+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53834+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
53835+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
53836+ }
53837+#endif
53838+
53839+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53840+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53841+ executable_stack = EXSTACK_DISABLE_X;
53842+ current->personality &= ~READ_IMPLIES_EXEC;
53843+ } else
53844+#endif
53845+
53846 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53847 current->personality |= READ_IMPLIES_EXEC;
53848
53849@@ -819,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53850 #else
53851 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53852 #endif
53853+
53854+#ifdef CONFIG_PAX_RANDMMAP
53855+ /* PaX: randomize base address at the default exe base if requested */
53856+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53857+#ifdef CONFIG_SPARC64
53858+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53859+#else
53860+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53861+#endif
53862+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53863+ elf_flags |= MAP_FIXED;
53864+ }
53865+#endif
53866+
53867 }
53868
53869 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53870@@ -851,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53871 * allowed task size. Note that p_filesz must always be
53872 * <= p_memsz so it is only necessary to check p_memsz.
53873 */
53874- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53875- elf_ppnt->p_memsz > TASK_SIZE ||
53876- TASK_SIZE - elf_ppnt->p_memsz < k) {
53877+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53878+ elf_ppnt->p_memsz > pax_task_size ||
53879+ pax_task_size - elf_ppnt->p_memsz < k) {
53880 /* set_brk can never work. Avoid overflows. */
53881 send_sig(SIGKILL, current, 0);
53882 retval = -EINVAL;
53883@@ -892,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53884 goto out_free_dentry;
53885 }
53886 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53887- send_sig(SIGSEGV, current, 0);
53888- retval = -EFAULT; /* Nobody gets to see this, but.. */
53889- goto out_free_dentry;
53890+ /*
53891+ * This bss-zeroing can fail if the ELF
53892+ * file specifies odd protections. So
53893+ * we don't check the return value
53894+ */
53895 }
53896
53897+#ifdef CONFIG_PAX_RANDMMAP
53898+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53899+ unsigned long start, size, flags;
53900+ vm_flags_t vm_flags;
53901+
53902+ start = ELF_PAGEALIGN(elf_brk);
53903+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53904+ flags = MAP_FIXED | MAP_PRIVATE;
53905+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53906+
53907+ down_write(&current->mm->mmap_sem);
53908+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53909+ retval = -ENOMEM;
53910+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53911+// if (current->personality & ADDR_NO_RANDOMIZE)
53912+// vm_flags |= VM_READ | VM_MAYREAD;
53913+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53914+ retval = IS_ERR_VALUE(start) ? start : 0;
53915+ }
53916+ up_write(&current->mm->mmap_sem);
53917+ if (retval == 0)
53918+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53919+ if (retval < 0) {
53920+ send_sig(SIGKILL, current, 0);
53921+ goto out_free_dentry;
53922+ }
53923+ }
53924+#endif
53925+
53926 if (elf_interpreter) {
53927- unsigned long interp_map_addr = 0;
53928-
53929 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53930 interpreter,
53931- &interp_map_addr,
53932 load_bias);
53933 if (!IS_ERR((void *)elf_entry)) {
53934 /*
53935@@ -1124,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53936 * Decide what to dump of a segment, part, all or none.
53937 */
53938 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53939- unsigned long mm_flags)
53940+ unsigned long mm_flags, long signr)
53941 {
53942 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53943
53944@@ -1162,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53945 if (vma->vm_file == NULL)
53946 return 0;
53947
53948- if (FILTER(MAPPED_PRIVATE))
53949+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53950 goto whole;
53951
53952 /*
53953@@ -1387,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53954 {
53955 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53956 int i = 0;
53957- do
53958+ do {
53959 i += 2;
53960- while (auxv[i - 2] != AT_NULL);
53961+ } while (auxv[i - 2] != AT_NULL);
53962 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53963 }
53964
53965@@ -1398,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53966 {
53967 mm_segment_t old_fs = get_fs();
53968 set_fs(KERNEL_DS);
53969- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53970+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53971 set_fs(old_fs);
53972 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53973 }
53974@@ -2019,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53975 }
53976
53977 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53978- unsigned long mm_flags)
53979+ struct coredump_params *cprm)
53980 {
53981 struct vm_area_struct *vma;
53982 size_t size = 0;
53983
53984 for (vma = first_vma(current, gate_vma); vma != NULL;
53985 vma = next_vma(vma, gate_vma))
53986- size += vma_dump_size(vma, mm_flags);
53987+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53988 return size;
53989 }
53990
53991@@ -2119,7 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53992
53993 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53994
53995- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53996+ offset += elf_core_vma_data_size(gate_vma, cprm);
53997 offset += elf_core_extra_data_size();
53998 e_shoff = offset;
53999
54000@@ -2133,10 +2588,12 @@ static int elf_core_dump(struct coredump_params *cprm)
54001 offset = dataoff;
54002
54003 size += sizeof(*elf);
54004+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54005 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
54006 goto end_coredump;
54007
54008 size += sizeof(*phdr4note);
54009+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54010 if (size > cprm->limit
54011 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
54012 goto end_coredump;
54013@@ -2150,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54014 phdr.p_offset = offset;
54015 phdr.p_vaddr = vma->vm_start;
54016 phdr.p_paddr = 0;
54017- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
54018+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54019 phdr.p_memsz = vma->vm_end - vma->vm_start;
54020 offset += phdr.p_filesz;
54021 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
54022@@ -2161,6 +2618,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54023 phdr.p_align = ELF_EXEC_PAGESIZE;
54024
54025 size += sizeof(phdr);
54026+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54027 if (size > cprm->limit
54028 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
54029 goto end_coredump;
54030@@ -2185,7 +2643,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54031 unsigned long addr;
54032 unsigned long end;
54033
54034- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
54035+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
54036
54037 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
54038 struct page *page;
54039@@ -2194,6 +2652,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54040 page = get_dump_page(addr);
54041 if (page) {
54042 void *kaddr = kmap(page);
54043+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
54044 stop = ((size += PAGE_SIZE) > cprm->limit) ||
54045 !dump_write(cprm->file, kaddr,
54046 PAGE_SIZE);
54047@@ -2211,6 +2670,7 @@ static int elf_core_dump(struct coredump_params *cprm)
54048
54049 if (e_phnum == PN_XNUM) {
54050 size += sizeof(*shdr4extnum);
54051+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
54052 if (size > cprm->limit
54053 || !dump_write(cprm->file, shdr4extnum,
54054 sizeof(*shdr4extnum)))
54055@@ -2231,6 +2691,167 @@ out:
54056
54057 #endif /* CONFIG_ELF_CORE */
54058
54059+#ifdef CONFIG_PAX_MPROTECT
54060+/* PaX: non-PIC ELF libraries need relocations on their executable segments
54061+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
54062+ * we'll remove VM_MAYWRITE for good on RELRO segments.
54063+ *
54064+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
54065+ * basis because we want to allow the common case and not the special ones.
54066+ */
54067+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
54068+{
54069+ struct elfhdr elf_h;
54070+ struct elf_phdr elf_p;
54071+ unsigned long i;
54072+ unsigned long oldflags;
54073+ bool is_textrel_rw, is_textrel_rx, is_relro;
54074+
54075+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
54076+ return;
54077+
54078+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
54079+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
54080+
54081+#ifdef CONFIG_PAX_ELFRELOCS
54082+ /* possible TEXTREL */
54083+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
54084+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
54085+#else
54086+ is_textrel_rw = false;
54087+ is_textrel_rx = false;
54088+#endif
54089+
54090+ /* possible RELRO */
54091+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
54092+
54093+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
54094+ return;
54095+
54096+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54097+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54098+
54099+#ifdef CONFIG_PAX_ETEXECRELOCS
54100+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54101+#else
54102+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
54103+#endif
54104+
54105+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
54106+ !elf_check_arch(&elf_h) ||
54107+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54108+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54109+ return;
54110+
54111+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54112+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54113+ return;
54114+ switch (elf_p.p_type) {
54115+ case PT_DYNAMIC:
54116+ if (!is_textrel_rw && !is_textrel_rx)
54117+ continue;
54118+ i = 0UL;
54119+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
54120+ elf_dyn dyn;
54121+
54122+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
54123+ break;
54124+ if (dyn.d_tag == DT_NULL)
54125+ break;
54126+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
54127+ gr_log_textrel(vma);
54128+ if (is_textrel_rw)
54129+ vma->vm_flags |= VM_MAYWRITE;
54130+ else
54131+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
54132+ vma->vm_flags &= ~VM_MAYWRITE;
54133+ break;
54134+ }
54135+ i++;
54136+ }
54137+ is_textrel_rw = false;
54138+ is_textrel_rx = false;
54139+ continue;
54140+
54141+ case PT_GNU_RELRO:
54142+ if (!is_relro)
54143+ continue;
54144+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
54145+ vma->vm_flags &= ~VM_MAYWRITE;
54146+ is_relro = false;
54147+ continue;
54148+
54149+#ifdef CONFIG_PAX_PT_PAX_FLAGS
54150+ case PT_PAX_FLAGS: {
54151+ const char *msg_mprotect = "", *msg_emutramp = "";
54152+ char *buffer_lib, *buffer_exe;
54153+
54154+ if (elf_p.p_flags & PF_NOMPROTECT)
54155+ msg_mprotect = "MPROTECT disabled";
54156+
54157+#ifdef CONFIG_PAX_EMUTRAMP
54158+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
54159+ msg_emutramp = "EMUTRAMP enabled";
54160+#endif
54161+
54162+ if (!msg_mprotect[0] && !msg_emutramp[0])
54163+ continue;
54164+
54165+ if (!printk_ratelimit())
54166+ continue;
54167+
54168+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
54169+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
54170+ if (buffer_lib && buffer_exe) {
54171+ char *path_lib, *path_exe;
54172+
54173+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
54174+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
54175+
54176+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
54177+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
54178+
54179+ }
54180+ free_page((unsigned long)buffer_exe);
54181+ free_page((unsigned long)buffer_lib);
54182+ continue;
54183+ }
54184+#endif
54185+
54186+ }
54187+ }
54188+}
54189+#endif
54190+
54191+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
54192+
54193+extern int grsec_enable_log_rwxmaps;
54194+
54195+static void elf_handle_mmap(struct file *file)
54196+{
54197+ struct elfhdr elf_h;
54198+ struct elf_phdr elf_p;
54199+ unsigned long i;
54200+
54201+ if (!grsec_enable_log_rwxmaps)
54202+ return;
54203+
54204+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
54205+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
54206+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
54207+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
54208+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
54209+ return;
54210+
54211+ for (i = 0UL; i < elf_h.e_phnum; i++) {
54212+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
54213+ return;
54214+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
54215+ gr_log_ptgnustack(file);
54216+ }
54217+}
54218+#endif
54219+
54220 static int __init init_elf_binfmt(void)
54221 {
54222 register_binfmt(&elf_format);
54223diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
54224index d50bbe5..af3b649 100644
54225--- a/fs/binfmt_flat.c
54226+++ b/fs/binfmt_flat.c
54227@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
54228 realdatastart = (unsigned long) -ENOMEM;
54229 printk("Unable to allocate RAM for process data, errno %d\n",
54230 (int)-realdatastart);
54231+ down_write(&current->mm->mmap_sem);
54232 vm_munmap(textpos, text_len);
54233+ up_write(&current->mm->mmap_sem);
54234 ret = realdatastart;
54235 goto err;
54236 }
54237@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54238 }
54239 if (IS_ERR_VALUE(result)) {
54240 printk("Unable to read data+bss, errno %d\n", (int)-result);
54241+ down_write(&current->mm->mmap_sem);
54242 vm_munmap(textpos, text_len);
54243 vm_munmap(realdatastart, len);
54244+ up_write(&current->mm->mmap_sem);
54245 ret = result;
54246 goto err;
54247 }
54248@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
54249 }
54250 if (IS_ERR_VALUE(result)) {
54251 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
54252+ down_write(&current->mm->mmap_sem);
54253 vm_munmap(textpos, text_len + data_len + extra +
54254 MAX_SHARED_LIBS * sizeof(unsigned long));
54255+ up_write(&current->mm->mmap_sem);
54256 ret = result;
54257 goto err;
54258 }
54259diff --git a/fs/bio.c b/fs/bio.c
54260index c5eae72..599e3cf 100644
54261--- a/fs/bio.c
54262+++ b/fs/bio.c
54263@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
54264 /*
54265 * Overflow, abort
54266 */
54267- if (end < start)
54268+ if (end < start || end - start > INT_MAX - nr_pages)
54269 return ERR_PTR(-EINVAL);
54270
54271 nr_pages += end - start;
54272@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
54273 /*
54274 * Overflow, abort
54275 */
54276- if (end < start)
54277+ if (end < start || end - start > INT_MAX - nr_pages)
54278 return ERR_PTR(-EINVAL);
54279
54280 nr_pages += end - start;
54281@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
54282 const int read = bio_data_dir(bio) == READ;
54283 struct bio_map_data *bmd = bio->bi_private;
54284 int i;
54285- char *p = bmd->sgvecs[0].iov_base;
54286+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
54287
54288 bio_for_each_segment_all(bvec, bio, i) {
54289 char *addr = page_address(bvec->bv_page);
54290diff --git a/fs/block_dev.c b/fs/block_dev.c
54291index 85f5c85..d6f0b1a 100644
54292--- a/fs/block_dev.c
54293+++ b/fs/block_dev.c
54294@@ -658,7 +658,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
54295 else if (bdev->bd_contains == bdev)
54296 return true; /* is a whole device which isn't held */
54297
54298- else if (whole->bd_holder == bd_may_claim)
54299+ else if (whole->bd_holder == (void *)bd_may_claim)
54300 return true; /* is a partition of a device that is being partitioned */
54301 else if (whole->bd_holder != NULL)
54302 return false; /* is a partition of a held device */
54303diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
54304index 7fb054b..ad36c67 100644
54305--- a/fs/btrfs/ctree.c
54306+++ b/fs/btrfs/ctree.c
54307@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
54308 free_extent_buffer(buf);
54309 add_root_to_dirty_list(root);
54310 } else {
54311- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
54312- parent_start = parent->start;
54313- else
54314+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
54315+ if (parent)
54316+ parent_start = parent->start;
54317+ else
54318+ parent_start = 0;
54319+ } else
54320 parent_start = 0;
54321
54322 WARN_ON(trans->transid != btrfs_header_generation(parent));
54323diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
54324index f26f38c..3d0f149 100644
54325--- a/fs/btrfs/delayed-inode.c
54326+++ b/fs/btrfs/delayed-inode.c
54327@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
54328
54329 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
54330 {
54331- int seq = atomic_inc_return(&delayed_root->items_seq);
54332+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
54333 if ((atomic_dec_return(&delayed_root->items) <
54334 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
54335 waitqueue_active(&delayed_root->wait))
54336@@ -1391,7 +1391,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
54337 static int refs_newer(struct btrfs_delayed_root *delayed_root,
54338 int seq, int count)
54339 {
54340- int val = atomic_read(&delayed_root->items_seq);
54341+ int val = atomic_read_unchecked(&delayed_root->items_seq);
54342
54343 if (val < seq || val >= seq + count)
54344 return 1;
54345@@ -1408,7 +1408,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
54346 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
54347 return;
54348
54349- seq = atomic_read(&delayed_root->items_seq);
54350+ seq = atomic_read_unchecked(&delayed_root->items_seq);
54351
54352 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
54353 int ret;
54354diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
54355index 1d5c5f7..0ba0afc 100644
54356--- a/fs/btrfs/delayed-inode.h
54357+++ b/fs/btrfs/delayed-inode.h
54358@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
54359 */
54360 struct list_head prepare_list;
54361 atomic_t items; /* for delayed items */
54362- atomic_t items_seq; /* for delayed items */
54363+ atomic_unchecked_t items_seq; /* for delayed items */
54364 int nodes; /* for delayed nodes */
54365 wait_queue_head_t wait;
54366 };
54367@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
54368 struct btrfs_delayed_root *delayed_root)
54369 {
54370 atomic_set(&delayed_root->items, 0);
54371- atomic_set(&delayed_root->items_seq, 0);
54372+ atomic_set_unchecked(&delayed_root->items_seq, 0);
54373 delayed_root->nodes = 0;
54374 spin_lock_init(&delayed_root->lock);
54375 init_waitqueue_head(&delayed_root->wait);
54376diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
54377index 0f81d67..0ad55fe 100644
54378--- a/fs/btrfs/ioctl.c
54379+++ b/fs/btrfs/ioctl.c
54380@@ -3084,9 +3084,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54381 for (i = 0; i < num_types; i++) {
54382 struct btrfs_space_info *tmp;
54383
54384+ /* Don't copy in more than we allocated */
54385 if (!slot_count)
54386 break;
54387
54388+ slot_count--;
54389+
54390 info = NULL;
54391 rcu_read_lock();
54392 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
54393@@ -3108,10 +3111,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
54394 memcpy(dest, &space, sizeof(space));
54395 dest++;
54396 space_args.total_spaces++;
54397- slot_count--;
54398 }
54399- if (!slot_count)
54400- break;
54401 }
54402 up_read(&info->groups_sem);
54403 }
54404diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
54405index f0857e0..e7023c5 100644
54406--- a/fs/btrfs/super.c
54407+++ b/fs/btrfs/super.c
54408@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
54409 function, line, errstr);
54410 return;
54411 }
54412- ACCESS_ONCE(trans->transaction->aborted) = errno;
54413+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
54414 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
54415 }
54416 /*
54417diff --git a/fs/buffer.c b/fs/buffer.c
54418index d2a4d1b..df798ca 100644
54419--- a/fs/buffer.c
54420+++ b/fs/buffer.c
54421@@ -3367,7 +3367,7 @@ void __init buffer_init(void)
54422 bh_cachep = kmem_cache_create("buffer_head",
54423 sizeof(struct buffer_head), 0,
54424 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
54425- SLAB_MEM_SPREAD),
54426+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
54427 NULL);
54428
54429 /*
54430diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
54431index 622f469..e8d2d55 100644
54432--- a/fs/cachefiles/bind.c
54433+++ b/fs/cachefiles/bind.c
54434@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
54435 args);
54436
54437 /* start by checking things over */
54438- ASSERT(cache->fstop_percent >= 0 &&
54439- cache->fstop_percent < cache->fcull_percent &&
54440+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
54441 cache->fcull_percent < cache->frun_percent &&
54442 cache->frun_percent < 100);
54443
54444- ASSERT(cache->bstop_percent >= 0 &&
54445- cache->bstop_percent < cache->bcull_percent &&
54446+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
54447 cache->bcull_percent < cache->brun_percent &&
54448 cache->brun_percent < 100);
54449
54450diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
54451index 0a1467b..6a53245 100644
54452--- a/fs/cachefiles/daemon.c
54453+++ b/fs/cachefiles/daemon.c
54454@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
54455 if (n > buflen)
54456 return -EMSGSIZE;
54457
54458- if (copy_to_user(_buffer, buffer, n) != 0)
54459+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
54460 return -EFAULT;
54461
54462 return n;
54463@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
54464 if (test_bit(CACHEFILES_DEAD, &cache->flags))
54465 return -EIO;
54466
54467- if (datalen < 0 || datalen > PAGE_SIZE - 1)
54468+ if (datalen > PAGE_SIZE - 1)
54469 return -EOPNOTSUPP;
54470
54471 /* drag the command string into the kernel so we can parse it */
54472@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
54473 if (args[0] != '%' || args[1] != '\0')
54474 return -EINVAL;
54475
54476- if (fstop < 0 || fstop >= cache->fcull_percent)
54477+ if (fstop >= cache->fcull_percent)
54478 return cachefiles_daemon_range_error(cache, args);
54479
54480 cache->fstop_percent = fstop;
54481@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
54482 if (args[0] != '%' || args[1] != '\0')
54483 return -EINVAL;
54484
54485- if (bstop < 0 || bstop >= cache->bcull_percent)
54486+ if (bstop >= cache->bcull_percent)
54487 return cachefiles_daemon_range_error(cache, args);
54488
54489 cache->bstop_percent = bstop;
54490diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
54491index 4938251..7e01445 100644
54492--- a/fs/cachefiles/internal.h
54493+++ b/fs/cachefiles/internal.h
54494@@ -59,7 +59,7 @@ struct cachefiles_cache {
54495 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
54496 struct rb_root active_nodes; /* active nodes (can't be culled) */
54497 rwlock_t active_lock; /* lock for active_nodes */
54498- atomic_t gravecounter; /* graveyard uniquifier */
54499+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
54500 unsigned frun_percent; /* when to stop culling (% files) */
54501 unsigned fcull_percent; /* when to start culling (% files) */
54502 unsigned fstop_percent; /* when to stop allocating (% files) */
54503@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
54504 * proc.c
54505 */
54506 #ifdef CONFIG_CACHEFILES_HISTOGRAM
54507-extern atomic_t cachefiles_lookup_histogram[HZ];
54508-extern atomic_t cachefiles_mkdir_histogram[HZ];
54509-extern atomic_t cachefiles_create_histogram[HZ];
54510+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54511+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54512+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
54513
54514 extern int __init cachefiles_proc_init(void);
54515 extern void cachefiles_proc_cleanup(void);
54516 static inline
54517-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
54518+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
54519 {
54520 unsigned long jif = jiffies - start_jif;
54521 if (jif >= HZ)
54522 jif = HZ - 1;
54523- atomic_inc(&histogram[jif]);
54524+ atomic_inc_unchecked(&histogram[jif]);
54525 }
54526
54527 #else
54528diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
54529index 8c01c5fc..15f982e 100644
54530--- a/fs/cachefiles/namei.c
54531+++ b/fs/cachefiles/namei.c
54532@@ -317,7 +317,7 @@ try_again:
54533 /* first step is to make up a grave dentry in the graveyard */
54534 sprintf(nbuffer, "%08x%08x",
54535 (uint32_t) get_seconds(),
54536- (uint32_t) atomic_inc_return(&cache->gravecounter));
54537+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
54538
54539 /* do the multiway lock magic */
54540 trap = lock_rename(cache->graveyard, dir);
54541diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
54542index eccd339..4c1d995 100644
54543--- a/fs/cachefiles/proc.c
54544+++ b/fs/cachefiles/proc.c
54545@@ -14,9 +14,9 @@
54546 #include <linux/seq_file.h>
54547 #include "internal.h"
54548
54549-atomic_t cachefiles_lookup_histogram[HZ];
54550-atomic_t cachefiles_mkdir_histogram[HZ];
54551-atomic_t cachefiles_create_histogram[HZ];
54552+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54553+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54554+atomic_unchecked_t cachefiles_create_histogram[HZ];
54555
54556 /*
54557 * display the latency histogram
54558@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
54559 return 0;
54560 default:
54561 index = (unsigned long) v - 3;
54562- x = atomic_read(&cachefiles_lookup_histogram[index]);
54563- y = atomic_read(&cachefiles_mkdir_histogram[index]);
54564- z = atomic_read(&cachefiles_create_histogram[index]);
54565+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
54566+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
54567+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
54568 if (x == 0 && y == 0 && z == 0)
54569 return 0;
54570
54571diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
54572index 317f9ee..3d24511 100644
54573--- a/fs/cachefiles/rdwr.c
54574+++ b/fs/cachefiles/rdwr.c
54575@@ -966,7 +966,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
54576 old_fs = get_fs();
54577 set_fs(KERNEL_DS);
54578 ret = file->f_op->write(
54579- file, (const void __user *) data, len, &pos);
54580+ file, (const void __force_user *) data, len, &pos);
54581 set_fs(old_fs);
54582 kunmap(page);
54583 file_end_write(file);
54584diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
54585index f02d82b..2632cf86 100644
54586--- a/fs/ceph/dir.c
54587+++ b/fs/ceph/dir.c
54588@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
54589 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
54590 struct ceph_mds_client *mdsc = fsc->mdsc;
54591 unsigned frag = fpos_frag(filp->f_pos);
54592- int off = fpos_off(filp->f_pos);
54593+ unsigned int off = fpos_off(filp->f_pos);
54594 int err;
54595 u32 ftype;
54596 struct ceph_mds_reply_info_parsed *rinfo;
54597diff --git a/fs/ceph/super.c b/fs/ceph/super.c
54598index 7d377c9..3fb6559 100644
54599--- a/fs/ceph/super.c
54600+++ b/fs/ceph/super.c
54601@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
54602 /*
54603 * construct our own bdi so we can control readahead, etc.
54604 */
54605-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
54606+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
54607
54608 static int ceph_register_bdi(struct super_block *sb,
54609 struct ceph_fs_client *fsc)
54610@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
54611 default_backing_dev_info.ra_pages;
54612
54613 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
54614- atomic_long_inc_return(&bdi_seq));
54615+ atomic_long_inc_return_unchecked(&bdi_seq));
54616 if (!err)
54617 sb->s_bdi = &fsc->backing_dev_info;
54618 return err;
54619diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
54620index d597483..747901b 100644
54621--- a/fs/cifs/cifs_debug.c
54622+++ b/fs/cifs/cifs_debug.c
54623@@ -284,8 +284,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54624
54625 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
54626 #ifdef CONFIG_CIFS_STATS2
54627- atomic_set(&totBufAllocCount, 0);
54628- atomic_set(&totSmBufAllocCount, 0);
54629+ atomic_set_unchecked(&totBufAllocCount, 0);
54630+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54631 #endif /* CONFIG_CIFS_STATS2 */
54632 spin_lock(&cifs_tcp_ses_lock);
54633 list_for_each(tmp1, &cifs_tcp_ses_list) {
54634@@ -298,7 +298,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54635 tcon = list_entry(tmp3,
54636 struct cifs_tcon,
54637 tcon_list);
54638- atomic_set(&tcon->num_smbs_sent, 0);
54639+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
54640 if (server->ops->clear_stats)
54641 server->ops->clear_stats(tcon);
54642 }
54643@@ -330,8 +330,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54644 smBufAllocCount.counter, cifs_min_small);
54645 #ifdef CONFIG_CIFS_STATS2
54646 seq_printf(m, "Total Large %d Small %d Allocations\n",
54647- atomic_read(&totBufAllocCount),
54648- atomic_read(&totSmBufAllocCount));
54649+ atomic_read_unchecked(&totBufAllocCount),
54650+ atomic_read_unchecked(&totSmBufAllocCount));
54651 #endif /* CONFIG_CIFS_STATS2 */
54652
54653 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
54654@@ -360,7 +360,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54655 if (tcon->need_reconnect)
54656 seq_puts(m, "\tDISCONNECTED ");
54657 seq_printf(m, "\nSMBs: %d",
54658- atomic_read(&tcon->num_smbs_sent));
54659+ atomic_read_unchecked(&tcon->num_smbs_sent));
54660 if (server->ops->print_stats)
54661 server->ops->print_stats(m, tcon);
54662 }
54663diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
54664index 3752b9f..8db5569 100644
54665--- a/fs/cifs/cifsfs.c
54666+++ b/fs/cifs/cifsfs.c
54667@@ -1035,7 +1035,7 @@ cifs_init_request_bufs(void)
54668 */
54669 cifs_req_cachep = kmem_cache_create("cifs_request",
54670 CIFSMaxBufSize + max_hdr_size, 0,
54671- SLAB_HWCACHE_ALIGN, NULL);
54672+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
54673 if (cifs_req_cachep == NULL)
54674 return -ENOMEM;
54675
54676@@ -1062,7 +1062,7 @@ cifs_init_request_bufs(void)
54677 efficient to alloc 1 per page off the slab compared to 17K (5page)
54678 alloc of large cifs buffers even when page debugging is on */
54679 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
54680- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
54681+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
54682 NULL);
54683 if (cifs_sm_req_cachep == NULL) {
54684 mempool_destroy(cifs_req_poolp);
54685@@ -1147,8 +1147,8 @@ init_cifs(void)
54686 atomic_set(&bufAllocCount, 0);
54687 atomic_set(&smBufAllocCount, 0);
54688 #ifdef CONFIG_CIFS_STATS2
54689- atomic_set(&totBufAllocCount, 0);
54690- atomic_set(&totSmBufAllocCount, 0);
54691+ atomic_set_unchecked(&totBufAllocCount, 0);
54692+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54693 #endif /* CONFIG_CIFS_STATS2 */
54694
54695 atomic_set(&midCount, 0);
54696diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
54697index ea3a0b3..0194e39 100644
54698--- a/fs/cifs/cifsglob.h
54699+++ b/fs/cifs/cifsglob.h
54700@@ -752,35 +752,35 @@ struct cifs_tcon {
54701 __u16 Flags; /* optional support bits */
54702 enum statusEnum tidStatus;
54703 #ifdef CONFIG_CIFS_STATS
54704- atomic_t num_smbs_sent;
54705+ atomic_unchecked_t num_smbs_sent;
54706 union {
54707 struct {
54708- atomic_t num_writes;
54709- atomic_t num_reads;
54710- atomic_t num_flushes;
54711- atomic_t num_oplock_brks;
54712- atomic_t num_opens;
54713- atomic_t num_closes;
54714- atomic_t num_deletes;
54715- atomic_t num_mkdirs;
54716- atomic_t num_posixopens;
54717- atomic_t num_posixmkdirs;
54718- atomic_t num_rmdirs;
54719- atomic_t num_renames;
54720- atomic_t num_t2renames;
54721- atomic_t num_ffirst;
54722- atomic_t num_fnext;
54723- atomic_t num_fclose;
54724- atomic_t num_hardlinks;
54725- atomic_t num_symlinks;
54726- atomic_t num_locks;
54727- atomic_t num_acl_get;
54728- atomic_t num_acl_set;
54729+ atomic_unchecked_t num_writes;
54730+ atomic_unchecked_t num_reads;
54731+ atomic_unchecked_t num_flushes;
54732+ atomic_unchecked_t num_oplock_brks;
54733+ atomic_unchecked_t num_opens;
54734+ atomic_unchecked_t num_closes;
54735+ atomic_unchecked_t num_deletes;
54736+ atomic_unchecked_t num_mkdirs;
54737+ atomic_unchecked_t num_posixopens;
54738+ atomic_unchecked_t num_posixmkdirs;
54739+ atomic_unchecked_t num_rmdirs;
54740+ atomic_unchecked_t num_renames;
54741+ atomic_unchecked_t num_t2renames;
54742+ atomic_unchecked_t num_ffirst;
54743+ atomic_unchecked_t num_fnext;
54744+ atomic_unchecked_t num_fclose;
54745+ atomic_unchecked_t num_hardlinks;
54746+ atomic_unchecked_t num_symlinks;
54747+ atomic_unchecked_t num_locks;
54748+ atomic_unchecked_t num_acl_get;
54749+ atomic_unchecked_t num_acl_set;
54750 } cifs_stats;
54751 #ifdef CONFIG_CIFS_SMB2
54752 struct {
54753- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54754- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54755+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54756+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54757 } smb2_stats;
54758 #endif /* CONFIG_CIFS_SMB2 */
54759 } stats;
54760@@ -1081,7 +1081,7 @@ convert_delimiter(char *path, char delim)
54761 }
54762
54763 #ifdef CONFIG_CIFS_STATS
54764-#define cifs_stats_inc atomic_inc
54765+#define cifs_stats_inc atomic_inc_unchecked
54766
54767 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
54768 unsigned int bytes)
54769@@ -1446,8 +1446,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
54770 /* Various Debug counters */
54771 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
54772 #ifdef CONFIG_CIFS_STATS2
54773-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
54774-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
54775+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
54776+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
54777 #endif
54778 GLOBAL_EXTERN atomic_t smBufAllocCount;
54779 GLOBAL_EXTERN atomic_t midCount;
54780diff --git a/fs/cifs/link.c b/fs/cifs/link.c
54781index b83c3f5..6437caa 100644
54782--- a/fs/cifs/link.c
54783+++ b/fs/cifs/link.c
54784@@ -616,7 +616,7 @@ symlink_exit:
54785
54786 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
54787 {
54788- char *p = nd_get_link(nd);
54789+ const char *p = nd_get_link(nd);
54790 if (!IS_ERR(p))
54791 kfree(p);
54792 }
54793diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
54794index 1bec014..f329411 100644
54795--- a/fs/cifs/misc.c
54796+++ b/fs/cifs/misc.c
54797@@ -169,7 +169,7 @@ cifs_buf_get(void)
54798 memset(ret_buf, 0, buf_size + 3);
54799 atomic_inc(&bufAllocCount);
54800 #ifdef CONFIG_CIFS_STATS2
54801- atomic_inc(&totBufAllocCount);
54802+ atomic_inc_unchecked(&totBufAllocCount);
54803 #endif /* CONFIG_CIFS_STATS2 */
54804 }
54805
54806@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
54807 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
54808 atomic_inc(&smBufAllocCount);
54809 #ifdef CONFIG_CIFS_STATS2
54810- atomic_inc(&totSmBufAllocCount);
54811+ atomic_inc_unchecked(&totSmBufAllocCount);
54812 #endif /* CONFIG_CIFS_STATS2 */
54813
54814 }
54815diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
54816index 3efdb9d..e845a5e 100644
54817--- a/fs/cifs/smb1ops.c
54818+++ b/fs/cifs/smb1ops.c
54819@@ -591,27 +591,27 @@ static void
54820 cifs_clear_stats(struct cifs_tcon *tcon)
54821 {
54822 #ifdef CONFIG_CIFS_STATS
54823- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
54824- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
54825- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
54826- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54827- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
54828- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
54829- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54830- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
54831- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
54832- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
54833- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
54834- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
54835- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
54836- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
54837- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
54838- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
54839- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54840- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54841- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54842- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54843- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54844+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54845+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54846+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54847+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54848+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54849+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54850+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54851+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54852+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54853+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54854+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54855+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54856+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54857+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54858+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54859+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54860+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54861+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54862+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54863+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54864+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54865 #endif
54866 }
54867
54868@@ -620,36 +620,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54869 {
54870 #ifdef CONFIG_CIFS_STATS
54871 seq_printf(m, " Oplocks breaks: %d",
54872- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54873+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54874 seq_printf(m, "\nReads: %d Bytes: %llu",
54875- atomic_read(&tcon->stats.cifs_stats.num_reads),
54876+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54877 (long long)(tcon->bytes_read));
54878 seq_printf(m, "\nWrites: %d Bytes: %llu",
54879- atomic_read(&tcon->stats.cifs_stats.num_writes),
54880+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54881 (long long)(tcon->bytes_written));
54882 seq_printf(m, "\nFlushes: %d",
54883- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54884+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54885 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54886- atomic_read(&tcon->stats.cifs_stats.num_locks),
54887- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54888- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54889+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54890+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54891+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54892 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54893- atomic_read(&tcon->stats.cifs_stats.num_opens),
54894- atomic_read(&tcon->stats.cifs_stats.num_closes),
54895- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54897+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54898+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54899 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54900- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54901- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54902+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54903+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54904 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54905- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54906- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54907+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54908+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54909 seq_printf(m, "\nRenames: %d T2 Renames %d",
54910- atomic_read(&tcon->stats.cifs_stats.num_renames),
54911- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54912+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54913+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54914 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54915- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54916- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54917- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54918+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54919+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54920+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54921 #endif
54922 }
54923
54924diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54925index f2e76f3..c44fac7 100644
54926--- a/fs/cifs/smb2ops.c
54927+++ b/fs/cifs/smb2ops.c
54928@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54929 #ifdef CONFIG_CIFS_STATS
54930 int i;
54931 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54932- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54933- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54934+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54935+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54936 }
54937 #endif
54938 }
54939@@ -284,66 +284,66 @@ static void
54940 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54941 {
54942 #ifdef CONFIG_CIFS_STATS
54943- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54944- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54945+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54946+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54947 seq_printf(m, "\nNegotiates: %d sent %d failed",
54948- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54949- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54950+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54951+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54952 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54953- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54954- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54955+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54956+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54957 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
54958 seq_printf(m, "\nLogoffs: %d sent %d failed",
54959- atomic_read(&sent[SMB2_LOGOFF_HE]),
54960- atomic_read(&failed[SMB2_LOGOFF_HE]));
54961+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54962+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54963 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54964- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54965- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54966+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54967+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54968 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54969- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54970- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54971+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54972+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54973 seq_printf(m, "\nCreates: %d sent %d failed",
54974- atomic_read(&sent[SMB2_CREATE_HE]),
54975- atomic_read(&failed[SMB2_CREATE_HE]));
54976+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54977+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54978 seq_printf(m, "\nCloses: %d sent %d failed",
54979- atomic_read(&sent[SMB2_CLOSE_HE]),
54980- atomic_read(&failed[SMB2_CLOSE_HE]));
54981+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54982+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54983 seq_printf(m, "\nFlushes: %d sent %d failed",
54984- atomic_read(&sent[SMB2_FLUSH_HE]),
54985- atomic_read(&failed[SMB2_FLUSH_HE]));
54986+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54987+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54988 seq_printf(m, "\nReads: %d sent %d failed",
54989- atomic_read(&sent[SMB2_READ_HE]),
54990- atomic_read(&failed[SMB2_READ_HE]));
54991+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54992+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54993 seq_printf(m, "\nWrites: %d sent %d failed",
54994- atomic_read(&sent[SMB2_WRITE_HE]),
54995- atomic_read(&failed[SMB2_WRITE_HE]));
54996+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54997+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54998 seq_printf(m, "\nLocks: %d sent %d failed",
54999- atomic_read(&sent[SMB2_LOCK_HE]),
55000- atomic_read(&failed[SMB2_LOCK_HE]));
55001+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
55002+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
55003 seq_printf(m, "\nIOCTLs: %d sent %d failed",
55004- atomic_read(&sent[SMB2_IOCTL_HE]),
55005- atomic_read(&failed[SMB2_IOCTL_HE]));
55006+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
55007+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
55008 seq_printf(m, "\nCancels: %d sent %d failed",
55009- atomic_read(&sent[SMB2_CANCEL_HE]),
55010- atomic_read(&failed[SMB2_CANCEL_HE]));
55011+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
55012+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
55013 seq_printf(m, "\nEchos: %d sent %d failed",
55014- atomic_read(&sent[SMB2_ECHO_HE]),
55015- atomic_read(&failed[SMB2_ECHO_HE]));
55016+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
55017+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
55018 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
55019- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
55020- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
55021+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
55022+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
55023 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
55024- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
55025- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
55026+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
55027+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
55028 seq_printf(m, "\nQueryInfos: %d sent %d failed",
55029- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
55030- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
55031+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
55032+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
55033 seq_printf(m, "\nSetInfos: %d sent %d failed",
55034- atomic_read(&sent[SMB2_SET_INFO_HE]),
55035- atomic_read(&failed[SMB2_SET_INFO_HE]));
55036+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
55037+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
55038 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
55039- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
55040- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
55041+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
55042+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
55043 #endif
55044 }
55045
55046diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
55047index 2b95ce2..d079d75 100644
55048--- a/fs/cifs/smb2pdu.c
55049+++ b/fs/cifs/smb2pdu.c
55050@@ -1760,8 +1760,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
55051 default:
55052 cifs_dbg(VFS, "info level %u isn't supported\n",
55053 srch_inf->info_level);
55054- rc = -EINVAL;
55055- goto qdir_exit;
55056+ return -EINVAL;
55057 }
55058
55059 req->FileIndex = cpu_to_le32(index);
55060diff --git a/fs/coda/cache.c b/fs/coda/cache.c
55061index 1da168c..8bc7ff6 100644
55062--- a/fs/coda/cache.c
55063+++ b/fs/coda/cache.c
55064@@ -24,7 +24,7 @@
55065 #include "coda_linux.h"
55066 #include "coda_cache.h"
55067
55068-static atomic_t permission_epoch = ATOMIC_INIT(0);
55069+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
55070
55071 /* replace or extend an acl cache hit */
55072 void coda_cache_enter(struct inode *inode, int mask)
55073@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
55074 struct coda_inode_info *cii = ITOC(inode);
55075
55076 spin_lock(&cii->c_lock);
55077- cii->c_cached_epoch = atomic_read(&permission_epoch);
55078+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
55079 if (!uid_eq(cii->c_uid, current_fsuid())) {
55080 cii->c_uid = current_fsuid();
55081 cii->c_cached_perm = mask;
55082@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
55083 {
55084 struct coda_inode_info *cii = ITOC(inode);
55085 spin_lock(&cii->c_lock);
55086- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
55087+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
55088 spin_unlock(&cii->c_lock);
55089 }
55090
55091 /* remove all acl caches */
55092 void coda_cache_clear_all(struct super_block *sb)
55093 {
55094- atomic_inc(&permission_epoch);
55095+ atomic_inc_unchecked(&permission_epoch);
55096 }
55097
55098
55099@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
55100 spin_lock(&cii->c_lock);
55101 hit = (mask & cii->c_cached_perm) == mask &&
55102 uid_eq(cii->c_uid, current_fsuid()) &&
55103- cii->c_cached_epoch == atomic_read(&permission_epoch);
55104+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
55105 spin_unlock(&cii->c_lock);
55106
55107 return hit;
55108diff --git a/fs/compat.c b/fs/compat.c
55109index fc3b55d..7b568ae 100644
55110--- a/fs/compat.c
55111+++ b/fs/compat.c
55112@@ -54,7 +54,7 @@
55113 #include <asm/ioctls.h>
55114 #include "internal.h"
55115
55116-int compat_log = 1;
55117+int compat_log = 0;
55118
55119 int compat_printk(const char *fmt, ...)
55120 {
55121@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
55122
55123 set_fs(KERNEL_DS);
55124 /* The __user pointer cast is valid because of the set_fs() */
55125- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
55126+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
55127 set_fs(oldfs);
55128 /* truncating is ok because it's a user address */
55129 if (!ret)
55130@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
55131 goto out;
55132
55133 ret = -EINVAL;
55134- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
55135+ if (nr_segs > UIO_MAXIOV)
55136 goto out;
55137 if (nr_segs > fast_segs) {
55138 ret = -ENOMEM;
55139@@ -833,6 +833,7 @@ struct compat_old_linux_dirent {
55140
55141 struct compat_readdir_callback {
55142 struct compat_old_linux_dirent __user *dirent;
55143+ struct file * file;
55144 int result;
55145 };
55146
55147@@ -850,6 +851,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
55148 buf->result = -EOVERFLOW;
55149 return -EOVERFLOW;
55150 }
55151+
55152+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55153+ return 0;
55154+
55155 buf->result++;
55156 dirent = buf->dirent;
55157 if (!access_ok(VERIFY_WRITE, dirent,
55158@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
55159
55160 buf.result = 0;
55161 buf.dirent = dirent;
55162+ buf.file = f.file;
55163
55164 error = vfs_readdir(f.file, compat_fillonedir, &buf);
55165 if (buf.result)
55166@@ -899,6 +905,7 @@ struct compat_linux_dirent {
55167 struct compat_getdents_callback {
55168 struct compat_linux_dirent __user *current_dir;
55169 struct compat_linux_dirent __user *previous;
55170+ struct file * file;
55171 int count;
55172 int error;
55173 };
55174@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
55175 buf->error = -EOVERFLOW;
55176 return -EOVERFLOW;
55177 }
55178+
55179+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55180+ return 0;
55181+
55182 dirent = buf->previous;
55183 if (dirent) {
55184 if (__put_user(offset, &dirent->d_off))
55185@@ -965,6 +976,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
55186 buf.previous = NULL;
55187 buf.count = count;
55188 buf.error = 0;
55189+ buf.file = f.file;
55190
55191 error = vfs_readdir(f.file, compat_filldir, &buf);
55192 if (error >= 0)
55193@@ -985,6 +997,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
55194 struct compat_getdents_callback64 {
55195 struct linux_dirent64 __user *current_dir;
55196 struct linux_dirent64 __user *previous;
55197+ struct file * file;
55198 int count;
55199 int error;
55200 };
55201@@ -1001,6 +1014,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
55202 buf->error = -EINVAL; /* only used if we fail.. */
55203 if (reclen > buf->count)
55204 return -EINVAL;
55205+
55206+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55207+ return 0;
55208+
55209 dirent = buf->previous;
55210
55211 if (dirent) {
55212@@ -1050,13 +1067,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
55213 buf.previous = NULL;
55214 buf.count = count;
55215 buf.error = 0;
55216+ buf.file = f.file;
55217
55218 error = vfs_readdir(f.file, compat_filldir64, &buf);
55219 if (error >= 0)
55220 error = buf.error;
55221 lastdirent = buf.previous;
55222 if (lastdirent) {
55223- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55224+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55225 if (__put_user_unaligned(d_off, &lastdirent->d_off))
55226 error = -EFAULT;
55227 else
55228diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
55229index a81147e..20bf2b5 100644
55230--- a/fs/compat_binfmt_elf.c
55231+++ b/fs/compat_binfmt_elf.c
55232@@ -30,11 +30,13 @@
55233 #undef elf_phdr
55234 #undef elf_shdr
55235 #undef elf_note
55236+#undef elf_dyn
55237 #undef elf_addr_t
55238 #define elfhdr elf32_hdr
55239 #define elf_phdr elf32_phdr
55240 #define elf_shdr elf32_shdr
55241 #define elf_note elf32_note
55242+#define elf_dyn Elf32_Dyn
55243 #define elf_addr_t Elf32_Addr
55244
55245 /*
55246diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
55247index 996cdc5..15e2f33 100644
55248--- a/fs/compat_ioctl.c
55249+++ b/fs/compat_ioctl.c
55250@@ -622,7 +622,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
55251 return -EFAULT;
55252 if (__get_user(udata, &ss32->iomem_base))
55253 return -EFAULT;
55254- ss.iomem_base = compat_ptr(udata);
55255+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
55256 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
55257 __get_user(ss.port_high, &ss32->port_high))
55258 return -EFAULT;
55259@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
55260 for (i = 0; i < nmsgs; i++) {
55261 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
55262 return -EFAULT;
55263- if (get_user(datap, &umsgs[i].buf) ||
55264- put_user(compat_ptr(datap), &tmsgs[i].buf))
55265+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
55266+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
55267 return -EFAULT;
55268 }
55269 return sys_ioctl(fd, cmd, (unsigned long)tdata);
55270@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
55271 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
55272 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
55273 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
55274- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55275+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
55276 return -EFAULT;
55277
55278 return ioctl_preallocate(file, p);
55279@@ -1619,8 +1619,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
55280 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
55281 {
55282 unsigned int a, b;
55283- a = *(unsigned int *)p;
55284- b = *(unsigned int *)q;
55285+ a = *(const unsigned int *)p;
55286+ b = *(const unsigned int *)q;
55287 if (a > b)
55288 return 1;
55289 if (a < b)
55290diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
55291index 7aabc6a..34c1197 100644
55292--- a/fs/configfs/dir.c
55293+++ b/fs/configfs/dir.c
55294@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
55295 }
55296 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
55297 struct configfs_dirent *next;
55298- const char * name;
55299+ const unsigned char * name;
55300+ char d_name[sizeof(next->s_dentry->d_iname)];
55301 int len;
55302 struct inode *inode = NULL;
55303
55304@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
55305 continue;
55306
55307 name = configfs_get_name(next);
55308- len = strlen(name);
55309+ if (next->s_dentry && name == next->s_dentry->d_iname) {
55310+ len = next->s_dentry->d_name.len;
55311+ memcpy(d_name, name, len);
55312+ name = d_name;
55313+ } else
55314+ len = strlen(name);
55315
55316 /*
55317 * We'll have a dentry and an inode for
55318diff --git a/fs/coredump.c b/fs/coredump.c
55319index dafafba..10b3b27 100644
55320--- a/fs/coredump.c
55321+++ b/fs/coredump.c
55322@@ -52,7 +52,7 @@ struct core_name {
55323 char *corename;
55324 int used, size;
55325 };
55326-static atomic_t call_count = ATOMIC_INIT(1);
55327+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
55328
55329 /* The maximal length of core_pattern is also specified in sysctl.c */
55330
55331@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
55332 {
55333 char *old_corename = cn->corename;
55334
55335- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
55336+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
55337 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
55338
55339 if (!cn->corename) {
55340@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
55341 int pid_in_pattern = 0;
55342 int err = 0;
55343
55344- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
55345+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
55346 cn->corename = kmalloc(cn->size, GFP_KERNEL);
55347 cn->used = 0;
55348
55349@@ -435,8 +435,8 @@ static void wait_for_dump_helpers(struct file *file)
55350 struct pipe_inode_info *pipe = file->private_data;
55351
55352 pipe_lock(pipe);
55353- pipe->readers++;
55354- pipe->writers--;
55355+ atomic_inc(&pipe->readers);
55356+ atomic_dec(&pipe->writers);
55357 wake_up_interruptible_sync(&pipe->wait);
55358 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
55359 pipe_unlock(pipe);
55360@@ -445,11 +445,11 @@ static void wait_for_dump_helpers(struct file *file)
55361 * We actually want wait_event_freezable() but then we need
55362 * to clear TIF_SIGPENDING and improve dump_interrupted().
55363 */
55364- wait_event_interruptible(pipe->wait, pipe->readers == 1);
55365+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
55366
55367 pipe_lock(pipe);
55368- pipe->readers--;
55369- pipe->writers++;
55370+ atomic_dec(&pipe->readers);
55371+ atomic_inc(&pipe->writers);
55372 pipe_unlock(pipe);
55373 }
55374
55375@@ -496,7 +496,8 @@ void do_coredump(siginfo_t *siginfo)
55376 struct files_struct *displaced;
55377 bool need_nonrelative = false;
55378 bool core_dumped = false;
55379- static atomic_t core_dump_count = ATOMIC_INIT(0);
55380+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
55381+ long signr = siginfo->si_signo;
55382 struct coredump_params cprm = {
55383 .siginfo = siginfo,
55384 .regs = signal_pt_regs(),
55385@@ -509,7 +510,10 @@ void do_coredump(siginfo_t *siginfo)
55386 .mm_flags = mm->flags,
55387 };
55388
55389- audit_core_dumps(siginfo->si_signo);
55390+ audit_core_dumps(signr);
55391+
55392+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
55393+ gr_handle_brute_attach(cprm.mm_flags);
55394
55395 binfmt = mm->binfmt;
55396 if (!binfmt || !binfmt->core_dump)
55397@@ -533,7 +537,7 @@ void do_coredump(siginfo_t *siginfo)
55398 need_nonrelative = true;
55399 }
55400
55401- retval = coredump_wait(siginfo->si_signo, &core_state);
55402+ retval = coredump_wait(signr, &core_state);
55403 if (retval < 0)
55404 goto fail_creds;
55405
55406@@ -576,7 +580,7 @@ void do_coredump(siginfo_t *siginfo)
55407 }
55408 cprm.limit = RLIM_INFINITY;
55409
55410- dump_count = atomic_inc_return(&core_dump_count);
55411+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
55412 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
55413 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
55414 task_tgid_vnr(current), current->comm);
55415@@ -608,6 +612,8 @@ void do_coredump(siginfo_t *siginfo)
55416 } else {
55417 struct inode *inode;
55418
55419+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
55420+
55421 if (cprm.limit < binfmt->min_coredump)
55422 goto fail_unlock;
55423
55424@@ -666,7 +672,7 @@ close_fail:
55425 filp_close(cprm.file, NULL);
55426 fail_dropcount:
55427 if (ispipe)
55428- atomic_dec(&core_dump_count);
55429+ atomic_dec_unchecked(&core_dump_count);
55430 fail_unlock:
55431 kfree(cn.corename);
55432 fail_corename:
55433@@ -687,7 +693,7 @@ int dump_write(struct file *file, const void *addr, int nr)
55434 {
55435 return !dump_interrupted() &&
55436 access_ok(VERIFY_READ, addr, nr) &&
55437- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
55438+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
55439 }
55440 EXPORT_SYMBOL(dump_write);
55441
55442diff --git a/fs/dcache.c b/fs/dcache.c
55443index f09b908..04b9690 100644
55444--- a/fs/dcache.c
55445+++ b/fs/dcache.c
55446@@ -3086,7 +3086,8 @@ void __init vfs_caches_init(unsigned long mempages)
55447 mempages -= reserve;
55448
55449 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
55450- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
55451+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
55452+ SLAB_NO_SANITIZE, NULL);
55453
55454 dcache_init();
55455 inode_init();
55456diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
55457index c7c83ff..bda9461 100644
55458--- a/fs/debugfs/inode.c
55459+++ b/fs/debugfs/inode.c
55460@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
55461 */
55462 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
55463 {
55464+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55465+ return __create_file(name, S_IFDIR | S_IRWXU,
55466+#else
55467 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
55468+#endif
55469 parent, NULL, NULL);
55470 }
55471 EXPORT_SYMBOL_GPL(debugfs_create_dir);
55472diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
55473index 5eab400..810a3f5 100644
55474--- a/fs/ecryptfs/inode.c
55475+++ b/fs/ecryptfs/inode.c
55476@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
55477 old_fs = get_fs();
55478 set_fs(get_ds());
55479 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
55480- (char __user *)lower_buf,
55481+ (char __force_user *)lower_buf,
55482 PATH_MAX);
55483 set_fs(old_fs);
55484 if (rc < 0)
55485@@ -706,7 +706,7 @@ out:
55486 static void
55487 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
55488 {
55489- char *buf = nd_get_link(nd);
55490+ const char *buf = nd_get_link(nd);
55491 if (!IS_ERR(buf)) {
55492 /* Free the char* */
55493 kfree(buf);
55494diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
55495index e4141f2..d8263e8 100644
55496--- a/fs/ecryptfs/miscdev.c
55497+++ b/fs/ecryptfs/miscdev.c
55498@@ -304,7 +304,7 @@ check_list:
55499 goto out_unlock_msg_ctx;
55500 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
55501 if (msg_ctx->msg) {
55502- if (copy_to_user(&buf[i], packet_length, packet_length_size))
55503+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
55504 goto out_unlock_msg_ctx;
55505 i += packet_length_size;
55506 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
55507diff --git a/fs/exec.c b/fs/exec.c
55508index 1f44670..3c84660 100644
55509--- a/fs/exec.c
55510+++ b/fs/exec.c
55511@@ -55,8 +55,20 @@
55512 #include <linux/pipe_fs_i.h>
55513 #include <linux/oom.h>
55514 #include <linux/compat.h>
55515+#include <linux/random.h>
55516+#include <linux/seq_file.h>
55517+#include <linux/coredump.h>
55518+#include <linux/mman.h>
55519+
55520+#ifdef CONFIG_PAX_REFCOUNT
55521+#include <linux/kallsyms.h>
55522+#include <linux/kdebug.h>
55523+#endif
55524+
55525+#include <trace/events/fs.h>
55526
55527 #include <asm/uaccess.h>
55528+#include <asm/sections.h>
55529 #include <asm/mmu_context.h>
55530 #include <asm/tlb.h>
55531
55532@@ -66,17 +78,32 @@
55533
55534 #include <trace/events/sched.h>
55535
55536+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55537+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
55538+{
55539+ 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");
55540+}
55541+#endif
55542+
55543+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
55544+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
55545+EXPORT_SYMBOL(pax_set_initial_flags_func);
55546+#endif
55547+
55548 int suid_dumpable = 0;
55549
55550 static LIST_HEAD(formats);
55551 static DEFINE_RWLOCK(binfmt_lock);
55552
55553+extern int gr_process_kernel_exec_ban(void);
55554+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
55555+
55556 void __register_binfmt(struct linux_binfmt * fmt, int insert)
55557 {
55558 BUG_ON(!fmt);
55559 write_lock(&binfmt_lock);
55560- insert ? list_add(&fmt->lh, &formats) :
55561- list_add_tail(&fmt->lh, &formats);
55562+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
55563+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
55564 write_unlock(&binfmt_lock);
55565 }
55566
55567@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
55568 void unregister_binfmt(struct linux_binfmt * fmt)
55569 {
55570 write_lock(&binfmt_lock);
55571- list_del(&fmt->lh);
55572+ pax_list_del((struct list_head *)&fmt->lh);
55573 write_unlock(&binfmt_lock);
55574 }
55575
55576@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55577 int write)
55578 {
55579 struct page *page;
55580- int ret;
55581
55582-#ifdef CONFIG_STACK_GROWSUP
55583- if (write) {
55584- ret = expand_downwards(bprm->vma, pos);
55585- if (ret < 0)
55586- return NULL;
55587- }
55588-#endif
55589- ret = get_user_pages(current, bprm->mm, pos,
55590- 1, write, 1, &page, NULL);
55591- if (ret <= 0)
55592+ if (0 > expand_downwards(bprm->vma, pos))
55593+ return NULL;
55594+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
55595 return NULL;
55596
55597 if (write) {
55598@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55599 if (size <= ARG_MAX)
55600 return page;
55601
55602+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55603+ // only allow 512KB for argv+env on suid/sgid binaries
55604+ // to prevent easy ASLR exhaustion
55605+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
55606+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
55607+ (size > (512 * 1024))) {
55608+ put_page(page);
55609+ return NULL;
55610+ }
55611+#endif
55612+
55613 /*
55614 * Limit to 1/4-th the stack size for the argv+env strings.
55615 * This ensures that:
55616@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55617 vma->vm_end = STACK_TOP_MAX;
55618 vma->vm_start = vma->vm_end - PAGE_SIZE;
55619 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
55620+
55621+#ifdef CONFIG_PAX_SEGMEXEC
55622+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
55623+#endif
55624+
55625 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
55626 INIT_LIST_HEAD(&vma->anon_vma_chain);
55627
55628@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55629 mm->stack_vm = mm->total_vm = 1;
55630 up_write(&mm->mmap_sem);
55631 bprm->p = vma->vm_end - sizeof(void *);
55632+
55633+#ifdef CONFIG_PAX_RANDUSTACK
55634+ if (randomize_va_space)
55635+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
55636+#endif
55637+
55638 return 0;
55639 err:
55640 up_write(&mm->mmap_sem);
55641@@ -396,7 +437,7 @@ struct user_arg_ptr {
55642 } ptr;
55643 };
55644
55645-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55646+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55647 {
55648 const char __user *native;
55649
55650@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55651 compat_uptr_t compat;
55652
55653 if (get_user(compat, argv.ptr.compat + nr))
55654- return ERR_PTR(-EFAULT);
55655+ return (const char __force_user *)ERR_PTR(-EFAULT);
55656
55657 return compat_ptr(compat);
55658 }
55659 #endif
55660
55661 if (get_user(native, argv.ptr.native + nr))
55662- return ERR_PTR(-EFAULT);
55663+ return (const char __force_user *)ERR_PTR(-EFAULT);
55664
55665 return native;
55666 }
55667@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
55668 if (!p)
55669 break;
55670
55671- if (IS_ERR(p))
55672+ if (IS_ERR((const char __force_kernel *)p))
55673 return -EFAULT;
55674
55675 if (i >= max)
55676@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
55677
55678 ret = -EFAULT;
55679 str = get_user_arg_ptr(argv, argc);
55680- if (IS_ERR(str))
55681+ if (IS_ERR((const char __force_kernel *)str))
55682 goto out;
55683
55684 len = strnlen_user(str, MAX_ARG_STRLEN);
55685@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
55686 int r;
55687 mm_segment_t oldfs = get_fs();
55688 struct user_arg_ptr argv = {
55689- .ptr.native = (const char __user *const __user *)__argv,
55690+ .ptr.native = (const char __force_user * const __force_user *)__argv,
55691 };
55692
55693 set_fs(KERNEL_DS);
55694@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55695 unsigned long new_end = old_end - shift;
55696 struct mmu_gather tlb;
55697
55698- BUG_ON(new_start > new_end);
55699+ if (new_start >= new_end || new_start < mmap_min_addr)
55700+ return -ENOMEM;
55701
55702 /*
55703 * ensure there are no vmas between where we want to go
55704@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55705 if (vma != find_vma(mm, new_start))
55706 return -EFAULT;
55707
55708+#ifdef CONFIG_PAX_SEGMEXEC
55709+ BUG_ON(pax_find_mirror_vma(vma));
55710+#endif
55711+
55712 /*
55713 * cover the whole range: [new_start, old_end)
55714 */
55715@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55716 stack_top = arch_align_stack(stack_top);
55717 stack_top = PAGE_ALIGN(stack_top);
55718
55719- if (unlikely(stack_top < mmap_min_addr) ||
55720- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
55721- return -ENOMEM;
55722-
55723 stack_shift = vma->vm_end - stack_top;
55724
55725 bprm->p -= stack_shift;
55726@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
55727 bprm->exec -= stack_shift;
55728
55729 down_write(&mm->mmap_sem);
55730+
55731+ /* Move stack pages down in memory. */
55732+ if (stack_shift) {
55733+ ret = shift_arg_pages(vma, stack_shift);
55734+ if (ret)
55735+ goto out_unlock;
55736+ }
55737+
55738 vm_flags = VM_STACK_FLAGS;
55739
55740+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55741+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55742+ vm_flags &= ~VM_EXEC;
55743+
55744+#ifdef CONFIG_PAX_MPROTECT
55745+ if (mm->pax_flags & MF_PAX_MPROTECT)
55746+ vm_flags &= ~VM_MAYEXEC;
55747+#endif
55748+
55749+ }
55750+#endif
55751+
55752 /*
55753 * Adjust stack execute permissions; explicitly enable for
55754 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
55755@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55756 goto out_unlock;
55757 BUG_ON(prev != vma);
55758
55759- /* Move stack pages down in memory. */
55760- if (stack_shift) {
55761- ret = shift_arg_pages(vma, stack_shift);
55762- if (ret)
55763- goto out_unlock;
55764- }
55765-
55766 /* mprotect_fixup is overkill to remove the temporary stack flags */
55767 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
55768
55769@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
55770 #endif
55771 current->mm->start_stack = bprm->p;
55772 ret = expand_stack(vma, stack_base);
55773+
55774+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
55775+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
55776+ unsigned long size;
55777+ vm_flags_t vm_flags;
55778+
55779+ size = STACK_TOP - vma->vm_end;
55780+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
55781+
55782+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
55783+
55784+#ifdef CONFIG_X86
55785+ if (!ret) {
55786+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
55787+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
55788+ }
55789+#endif
55790+
55791+ }
55792+#endif
55793+
55794 if (ret)
55795 ret = -EFAULT;
55796
55797@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
55798
55799 fsnotify_open(file);
55800
55801+ trace_open_exec(name);
55802+
55803 err = deny_write_access(file);
55804 if (err)
55805 goto exit;
55806@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
55807 old_fs = get_fs();
55808 set_fs(get_ds());
55809 /* The cast to a user pointer is valid due to the set_fs() */
55810- result = vfs_read(file, (void __user *)addr, count, &pos);
55811+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
55812 set_fs(old_fs);
55813 return result;
55814 }
55815@@ -1251,7 +1329,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
55816 }
55817 rcu_read_unlock();
55818
55819- if (p->fs->users > n_fs) {
55820+ if (atomic_read(&p->fs->users) > n_fs) {
55821 bprm->unsafe |= LSM_UNSAFE_SHARE;
55822 } else {
55823 res = -EAGAIN;
55824@@ -1451,6 +1529,31 @@ int search_binary_handler(struct linux_binprm *bprm)
55825
55826 EXPORT_SYMBOL(search_binary_handler);
55827
55828+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55829+static DEFINE_PER_CPU(u64, exec_counter);
55830+static int __init init_exec_counters(void)
55831+{
55832+ unsigned int cpu;
55833+
55834+ for_each_possible_cpu(cpu) {
55835+ per_cpu(exec_counter, cpu) = (u64)cpu;
55836+ }
55837+
55838+ return 0;
55839+}
55840+early_initcall(init_exec_counters);
55841+static inline void increment_exec_counter(void)
55842+{
55843+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
55844+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
55845+}
55846+#else
55847+static inline void increment_exec_counter(void) {}
55848+#endif
55849+
55850+extern void gr_handle_exec_args(struct linux_binprm *bprm,
55851+ struct user_arg_ptr argv);
55852+
55853 /*
55854 * sys_execve() executes a new program.
55855 */
55856@@ -1458,6 +1561,11 @@ static int do_execve_common(const char *filename,
55857 struct user_arg_ptr argv,
55858 struct user_arg_ptr envp)
55859 {
55860+#ifdef CONFIG_GRKERNSEC
55861+ struct file *old_exec_file;
55862+ struct acl_subject_label *old_acl;
55863+ struct rlimit old_rlim[RLIM_NLIMITS];
55864+#endif
55865 struct linux_binprm *bprm;
55866 struct file *file;
55867 struct files_struct *displaced;
55868@@ -1465,6 +1573,8 @@ static int do_execve_common(const char *filename,
55869 int retval;
55870 const struct cred *cred = current_cred();
55871
55872+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
55873+
55874 /*
55875 * We move the actual failure in case of RLIMIT_NPROC excess from
55876 * set*uid() to execve() because too many poorly written programs
55877@@ -1505,12 +1615,22 @@ static int do_execve_common(const char *filename,
55878 if (IS_ERR(file))
55879 goto out_unmark;
55880
55881+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55882+ retval = -EPERM;
55883+ goto out_file;
55884+ }
55885+
55886 sched_exec();
55887
55888 bprm->file = file;
55889 bprm->filename = filename;
55890 bprm->interp = filename;
55891
55892+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55893+ retval = -EACCES;
55894+ goto out_file;
55895+ }
55896+
55897 retval = bprm_mm_init(bprm);
55898 if (retval)
55899 goto out_file;
55900@@ -1527,24 +1647,70 @@ static int do_execve_common(const char *filename,
55901 if (retval < 0)
55902 goto out;
55903
55904+#ifdef CONFIG_GRKERNSEC
55905+ old_acl = current->acl;
55906+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55907+ old_exec_file = current->exec_file;
55908+ get_file(file);
55909+ current->exec_file = file;
55910+#endif
55911+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55912+ /* limit suid stack to 8MB
55913+ * we saved the old limits above and will restore them if this exec fails
55914+ */
55915+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55916+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55917+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55918+#endif
55919+
55920+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55921+ retval = -EPERM;
55922+ goto out_fail;
55923+ }
55924+
55925+ if (!gr_tpe_allow(file)) {
55926+ retval = -EACCES;
55927+ goto out_fail;
55928+ }
55929+
55930+ if (gr_check_crash_exec(file)) {
55931+ retval = -EACCES;
55932+ goto out_fail;
55933+ }
55934+
55935+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55936+ bprm->unsafe);
55937+ if (retval < 0)
55938+ goto out_fail;
55939+
55940 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55941 if (retval < 0)
55942- goto out;
55943+ goto out_fail;
55944
55945 bprm->exec = bprm->p;
55946 retval = copy_strings(bprm->envc, envp, bprm);
55947 if (retval < 0)
55948- goto out;
55949+ goto out_fail;
55950
55951 retval = copy_strings(bprm->argc, argv, bprm);
55952 if (retval < 0)
55953- goto out;
55954+ goto out_fail;
55955+
55956+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55957+
55958+ gr_handle_exec_args(bprm, argv);
55959
55960 retval = search_binary_handler(bprm);
55961 if (retval < 0)
55962- goto out;
55963+ goto out_fail;
55964+#ifdef CONFIG_GRKERNSEC
55965+ if (old_exec_file)
55966+ fput(old_exec_file);
55967+#endif
55968
55969 /* execve succeeded */
55970+
55971+ increment_exec_counter();
55972 current->fs->in_exec = 0;
55973 current->in_execve = 0;
55974 acct_update_integrals(current);
55975@@ -1553,6 +1719,14 @@ static int do_execve_common(const char *filename,
55976 put_files_struct(displaced);
55977 return retval;
55978
55979+out_fail:
55980+#ifdef CONFIG_GRKERNSEC
55981+ current->acl = old_acl;
55982+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55983+ fput(current->exec_file);
55984+ current->exec_file = old_exec_file;
55985+#endif
55986+
55987 out:
55988 if (bprm->mm) {
55989 acct_arg_size(bprm, 0);
55990@@ -1701,3 +1875,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55991 return error;
55992 }
55993 #endif
55994+
55995+int pax_check_flags(unsigned long *flags)
55996+{
55997+ int retval = 0;
55998+
55999+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
56000+ if (*flags & MF_PAX_SEGMEXEC)
56001+ {
56002+ *flags &= ~MF_PAX_SEGMEXEC;
56003+ retval = -EINVAL;
56004+ }
56005+#endif
56006+
56007+ if ((*flags & MF_PAX_PAGEEXEC)
56008+
56009+#ifdef CONFIG_PAX_PAGEEXEC
56010+ && (*flags & MF_PAX_SEGMEXEC)
56011+#endif
56012+
56013+ )
56014+ {
56015+ *flags &= ~MF_PAX_PAGEEXEC;
56016+ retval = -EINVAL;
56017+ }
56018+
56019+ if ((*flags & MF_PAX_MPROTECT)
56020+
56021+#ifdef CONFIG_PAX_MPROTECT
56022+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56023+#endif
56024+
56025+ )
56026+ {
56027+ *flags &= ~MF_PAX_MPROTECT;
56028+ retval = -EINVAL;
56029+ }
56030+
56031+ if ((*flags & MF_PAX_EMUTRAMP)
56032+
56033+#ifdef CONFIG_PAX_EMUTRAMP
56034+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
56035+#endif
56036+
56037+ )
56038+ {
56039+ *flags &= ~MF_PAX_EMUTRAMP;
56040+ retval = -EINVAL;
56041+ }
56042+
56043+ return retval;
56044+}
56045+
56046+EXPORT_SYMBOL(pax_check_flags);
56047+
56048+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56049+char *pax_get_path(const struct path *path, char *buf, int buflen)
56050+{
56051+ char *pathname = d_path(path, buf, buflen);
56052+
56053+ if (IS_ERR(pathname))
56054+ goto toolong;
56055+
56056+ pathname = mangle_path(buf, pathname, "\t\n\\");
56057+ if (!pathname)
56058+ goto toolong;
56059+
56060+ *pathname = 0;
56061+ return buf;
56062+
56063+toolong:
56064+ return "<path too long>";
56065+}
56066+EXPORT_SYMBOL(pax_get_path);
56067+
56068+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
56069+{
56070+ struct task_struct *tsk = current;
56071+ struct mm_struct *mm = current->mm;
56072+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
56073+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
56074+ char *path_exec = NULL;
56075+ char *path_fault = NULL;
56076+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
56077+ siginfo_t info = { };
56078+
56079+ if (buffer_exec && buffer_fault) {
56080+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
56081+
56082+ down_read(&mm->mmap_sem);
56083+ vma = mm->mmap;
56084+ while (vma && (!vma_exec || !vma_fault)) {
56085+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
56086+ vma_exec = vma;
56087+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
56088+ vma_fault = vma;
56089+ vma = vma->vm_next;
56090+ }
56091+ if (vma_exec)
56092+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
56093+ if (vma_fault) {
56094+ start = vma_fault->vm_start;
56095+ end = vma_fault->vm_end;
56096+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
56097+ if (vma_fault->vm_file)
56098+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
56099+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
56100+ path_fault = "<heap>";
56101+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
56102+ path_fault = "<stack>";
56103+ else
56104+ path_fault = "<anonymous mapping>";
56105+ }
56106+ up_read(&mm->mmap_sem);
56107+ }
56108+ if (tsk->signal->curr_ip)
56109+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
56110+ else
56111+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
56112+ 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),
56113+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
56114+ free_page((unsigned long)buffer_exec);
56115+ free_page((unsigned long)buffer_fault);
56116+ pax_report_insns(regs, pc, sp);
56117+ info.si_signo = SIGKILL;
56118+ info.si_errno = 0;
56119+ info.si_code = SI_KERNEL;
56120+ info.si_pid = 0;
56121+ info.si_uid = 0;
56122+ do_coredump(&info);
56123+}
56124+#endif
56125+
56126+#ifdef CONFIG_PAX_REFCOUNT
56127+void pax_report_refcount_overflow(struct pt_regs *regs)
56128+{
56129+ if (current->signal->curr_ip)
56130+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
56131+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
56132+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56133+ else
56134+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
56135+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
56136+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
56137+ preempt_disable();
56138+ show_regs(regs);
56139+ preempt_enable();
56140+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
56141+}
56142+#endif
56143+
56144+#ifdef CONFIG_PAX_USERCOPY
56145+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
56146+static noinline int check_stack_object(const void *obj, unsigned long len)
56147+{
56148+ const void * const stack = task_stack_page(current);
56149+ const void * const stackend = stack + THREAD_SIZE;
56150+
56151+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56152+ const void *frame = NULL;
56153+ const void *oldframe;
56154+#endif
56155+
56156+ if (obj + len < obj)
56157+ return -1;
56158+
56159+ if (obj + len <= stack || stackend <= obj)
56160+ return 0;
56161+
56162+ if (obj < stack || stackend < obj + len)
56163+ return -1;
56164+
56165+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
56166+ oldframe = __builtin_frame_address(1);
56167+ if (oldframe)
56168+ frame = __builtin_frame_address(2);
56169+ /*
56170+ low ----------------------------------------------> high
56171+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
56172+ ^----------------^
56173+ allow copies only within here
56174+ */
56175+ while (stack <= frame && frame < stackend) {
56176+ /* if obj + len extends past the last frame, this
56177+ check won't pass and the next frame will be 0,
56178+ causing us to bail out and correctly report
56179+ the copy as invalid
56180+ */
56181+ if (obj + len <= frame)
56182+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
56183+ oldframe = frame;
56184+ frame = *(const void * const *)frame;
56185+ }
56186+ return -1;
56187+#else
56188+ return 1;
56189+#endif
56190+}
56191+
56192+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
56193+{
56194+ if (current->signal->curr_ip)
56195+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56196+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56197+ else
56198+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
56199+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
56200+ dump_stack();
56201+ gr_handle_kernel_exploit();
56202+ do_group_exit(SIGKILL);
56203+}
56204+#endif
56205+
56206+#ifdef CONFIG_PAX_USERCOPY
56207+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
56208+{
56209+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
56210+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
56211+#ifdef CONFIG_MODULES
56212+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
56213+#else
56214+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
56215+#endif
56216+
56217+#else
56218+ unsigned long textlow = (unsigned long)_stext;
56219+ unsigned long texthigh = (unsigned long)_etext;
56220+#endif
56221+
56222+ if (high <= textlow || low > texthigh)
56223+ return false;
56224+ else
56225+ return true;
56226+}
56227+#endif
56228+
56229+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
56230+{
56231+
56232+#ifdef CONFIG_PAX_USERCOPY
56233+ const char *type;
56234+
56235+ if (!n)
56236+ return;
56237+
56238+ type = check_heap_object(ptr, n);
56239+ if (!type) {
56240+ int ret = check_stack_object(ptr, n);
56241+ if (ret == 1 || ret == 2)
56242+ return;
56243+ if (ret == 0) {
56244+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
56245+ type = "<kernel text>";
56246+ else
56247+ return;
56248+ } else
56249+ type = "<process stack>";
56250+ }
56251+
56252+ pax_report_usercopy(ptr, n, to_user, type);
56253+#endif
56254+
56255+}
56256+EXPORT_SYMBOL(__check_object_size);
56257+
56258+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
56259+void pax_track_stack(void)
56260+{
56261+ unsigned long sp = (unsigned long)&sp;
56262+ if (sp < current_thread_info()->lowest_stack &&
56263+ sp > (unsigned long)task_stack_page(current))
56264+ current_thread_info()->lowest_stack = sp;
56265+}
56266+EXPORT_SYMBOL(pax_track_stack);
56267+#endif
56268+
56269+#ifdef CONFIG_PAX_SIZE_OVERFLOW
56270+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
56271+{
56272+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
56273+ dump_stack();
56274+ do_group_exit(SIGKILL);
56275+}
56276+EXPORT_SYMBOL(report_size_overflow);
56277+#endif
56278diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
56279index 9f9992b..8b59411 100644
56280--- a/fs/ext2/balloc.c
56281+++ b/fs/ext2/balloc.c
56282@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
56283
56284 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56285 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56286- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56287+ if (free_blocks < root_blocks + 1 &&
56288 !uid_eq(sbi->s_resuid, current_fsuid()) &&
56289 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56290- !in_group_p (sbi->s_resgid))) {
56291+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56292 return 0;
56293 }
56294 return 1;
56295diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
56296index 22548f5..41521d8 100644
56297--- a/fs/ext3/balloc.c
56298+++ b/fs/ext3/balloc.c
56299@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
56300
56301 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
56302 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
56303- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
56304+ if (free_blocks < root_blocks + 1 &&
56305 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
56306 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
56307- !in_group_p (sbi->s_resgid))) {
56308+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
56309 return 0;
56310 }
56311 return 1;
56312diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
56313index 3742e4c..69a797f 100644
56314--- a/fs/ext4/balloc.c
56315+++ b/fs/ext4/balloc.c
56316@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
56317 /* Hm, nope. Are (enough) root reserved clusters available? */
56318 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
56319 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
56320- capable(CAP_SYS_RESOURCE) ||
56321- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
56322+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
56323+ capable_nolog(CAP_SYS_RESOURCE)) {
56324
56325 if (free_clusters >= (nclusters + dirty_clusters +
56326 resv_clusters))
56327diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
56328index 5aae3d1..b5da7f8 100644
56329--- a/fs/ext4/ext4.h
56330+++ b/fs/ext4/ext4.h
56331@@ -1252,19 +1252,19 @@ struct ext4_sb_info {
56332 unsigned long s_mb_last_start;
56333
56334 /* stats for buddy allocator */
56335- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
56336- atomic_t s_bal_success; /* we found long enough chunks */
56337- atomic_t s_bal_allocated; /* in blocks */
56338- atomic_t s_bal_ex_scanned; /* total extents scanned */
56339- atomic_t s_bal_goals; /* goal hits */
56340- atomic_t s_bal_breaks; /* too long searches */
56341- atomic_t s_bal_2orders; /* 2^order hits */
56342+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
56343+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
56344+ atomic_unchecked_t s_bal_allocated; /* in blocks */
56345+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
56346+ atomic_unchecked_t s_bal_goals; /* goal hits */
56347+ atomic_unchecked_t s_bal_breaks; /* too long searches */
56348+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
56349 spinlock_t s_bal_lock;
56350 unsigned long s_mb_buddies_generated;
56351 unsigned long long s_mb_generation_time;
56352- atomic_t s_mb_lost_chunks;
56353- atomic_t s_mb_preallocated;
56354- atomic_t s_mb_discarded;
56355+ atomic_unchecked_t s_mb_lost_chunks;
56356+ atomic_unchecked_t s_mb_preallocated;
56357+ atomic_unchecked_t s_mb_discarded;
56358 atomic_t s_lock_busy;
56359
56360 /* locality groups */
56361diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
56362index 59c6750..a549154 100644
56363--- a/fs/ext4/mballoc.c
56364+++ b/fs/ext4/mballoc.c
56365@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
56366 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
56367
56368 if (EXT4_SB(sb)->s_mb_stats)
56369- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
56370+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
56371
56372 break;
56373 }
56374@@ -2170,7 +2170,7 @@ repeat:
56375 ac->ac_status = AC_STATUS_CONTINUE;
56376 ac->ac_flags |= EXT4_MB_HINT_FIRST;
56377 cr = 3;
56378- atomic_inc(&sbi->s_mb_lost_chunks);
56379+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
56380 goto repeat;
56381 }
56382 }
56383@@ -2678,25 +2678,25 @@ int ext4_mb_release(struct super_block *sb)
56384 if (sbi->s_mb_stats) {
56385 ext4_msg(sb, KERN_INFO,
56386 "mballoc: %u blocks %u reqs (%u success)",
56387- atomic_read(&sbi->s_bal_allocated),
56388- atomic_read(&sbi->s_bal_reqs),
56389- atomic_read(&sbi->s_bal_success));
56390+ atomic_read_unchecked(&sbi->s_bal_allocated),
56391+ atomic_read_unchecked(&sbi->s_bal_reqs),
56392+ atomic_read_unchecked(&sbi->s_bal_success));
56393 ext4_msg(sb, KERN_INFO,
56394 "mballoc: %u extents scanned, %u goal hits, "
56395 "%u 2^N hits, %u breaks, %u lost",
56396- atomic_read(&sbi->s_bal_ex_scanned),
56397- atomic_read(&sbi->s_bal_goals),
56398- atomic_read(&sbi->s_bal_2orders),
56399- atomic_read(&sbi->s_bal_breaks),
56400- atomic_read(&sbi->s_mb_lost_chunks));
56401+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
56402+ atomic_read_unchecked(&sbi->s_bal_goals),
56403+ atomic_read_unchecked(&sbi->s_bal_2orders),
56404+ atomic_read_unchecked(&sbi->s_bal_breaks),
56405+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
56406 ext4_msg(sb, KERN_INFO,
56407 "mballoc: %lu generated and it took %Lu",
56408 sbi->s_mb_buddies_generated,
56409 sbi->s_mb_generation_time);
56410 ext4_msg(sb, KERN_INFO,
56411 "mballoc: %u preallocated, %u discarded",
56412- atomic_read(&sbi->s_mb_preallocated),
56413- atomic_read(&sbi->s_mb_discarded));
56414+ atomic_read_unchecked(&sbi->s_mb_preallocated),
56415+ atomic_read_unchecked(&sbi->s_mb_discarded));
56416 }
56417
56418 free_percpu(sbi->s_locality_groups);
56419@@ -3150,16 +3150,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
56420 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
56421
56422 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
56423- atomic_inc(&sbi->s_bal_reqs);
56424- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56425+ atomic_inc_unchecked(&sbi->s_bal_reqs);
56426+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
56427 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
56428- atomic_inc(&sbi->s_bal_success);
56429- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
56430+ atomic_inc_unchecked(&sbi->s_bal_success);
56431+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
56432 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
56433 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
56434- atomic_inc(&sbi->s_bal_goals);
56435+ atomic_inc_unchecked(&sbi->s_bal_goals);
56436 if (ac->ac_found > sbi->s_mb_max_to_scan)
56437- atomic_inc(&sbi->s_bal_breaks);
56438+ atomic_inc_unchecked(&sbi->s_bal_breaks);
56439 }
56440
56441 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
56442@@ -3559,7 +3559,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
56443 trace_ext4_mb_new_inode_pa(ac, pa);
56444
56445 ext4_mb_use_inode_pa(ac, pa);
56446- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
56447+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
56448
56449 ei = EXT4_I(ac->ac_inode);
56450 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56451@@ -3619,7 +3619,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
56452 trace_ext4_mb_new_group_pa(ac, pa);
56453
56454 ext4_mb_use_group_pa(ac, pa);
56455- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56456+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56457
56458 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56459 lg = ac->ac_lg;
56460@@ -3708,7 +3708,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
56461 * from the bitmap and continue.
56462 */
56463 }
56464- atomic_add(free, &sbi->s_mb_discarded);
56465+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
56466
56467 return err;
56468 }
56469@@ -3726,7 +3726,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
56470 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
56471 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
56472 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
56473- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56474+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56475 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
56476
56477 return 0;
56478diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
56479index 214461e..3614c89 100644
56480--- a/fs/ext4/mmp.c
56481+++ b/fs/ext4/mmp.c
56482@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
56483 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
56484 const char *function, unsigned int line, const char *msg)
56485 {
56486- __ext4_warning(sb, function, line, msg);
56487+ __ext4_warning(sb, function, line, "%s", msg);
56488 __ext4_warning(sb, function, line,
56489 "MMP failure info: last update time: %llu, last update "
56490 "node: %s, last update device: %s\n",
56491diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
56492index 49d3c01..9579efd 100644
56493--- a/fs/ext4/resize.c
56494+++ b/fs/ext4/resize.c
56495@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
56496 ext4_fsblk_t end = start + input->blocks_count;
56497 ext4_group_t group = input->group;
56498 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
56499- unsigned overhead = ext4_group_overhead_blocks(sb, group);
56500- ext4_fsblk_t metaend = start + overhead;
56501+ unsigned overhead;
56502+ ext4_fsblk_t metaend;
56503 struct buffer_head *bh = NULL;
56504 ext4_grpblk_t free_blocks_count, offset;
56505 int err = -EINVAL;
56506
56507+ if (group != sbi->s_groups_count) {
56508+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
56509+ input->group, sbi->s_groups_count);
56510+ return -EINVAL;
56511+ }
56512+
56513+ overhead = ext4_group_overhead_blocks(sb, group);
56514+ metaend = start + overhead;
56515 input->free_blocks_count = free_blocks_count =
56516 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
56517
56518@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
56519 free_blocks_count, input->reserved_blocks);
56520
56521 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
56522- if (group != sbi->s_groups_count)
56523- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
56524- input->group, sbi->s_groups_count);
56525- else if (offset != 0)
56526+ if (offset != 0)
56527 ext4_warning(sb, "Last group not full");
56528 else if (input->reserved_blocks > input->blocks_count / 5)
56529 ext4_warning(sb, "Reserved blocks too high (%u)",
56530diff --git a/fs/ext4/super.c b/fs/ext4/super.c
56531index 3f7c39e..227f24f 100644
56532--- a/fs/ext4/super.c
56533+++ b/fs/ext4/super.c
56534@@ -1236,7 +1236,7 @@ static ext4_fsblk_t get_sb_block(void **data)
56535 }
56536
56537 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
56538-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56539+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56540 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
56541
56542 #ifdef CONFIG_QUOTA
56543@@ -2372,7 +2372,7 @@ struct ext4_attr {
56544 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
56545 const char *, size_t);
56546 int offset;
56547-};
56548+} __do_const;
56549
56550 static int parse_strtoull(const char *buf,
56551 unsigned long long max, unsigned long long *value)
56552diff --git a/fs/fcntl.c b/fs/fcntl.c
56553index 6599222..e7bf0de 100644
56554--- a/fs/fcntl.c
56555+++ b/fs/fcntl.c
56556@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
56557 if (err)
56558 return err;
56559
56560+ if (gr_handle_chroot_fowner(pid, type))
56561+ return -ENOENT;
56562+ if (gr_check_protected_task_fowner(pid, type))
56563+ return -EACCES;
56564+
56565 f_modown(filp, pid, type, force);
56566 return 0;
56567 }
56568diff --git a/fs/fhandle.c b/fs/fhandle.c
56569index 999ff5c..41f4109 100644
56570--- a/fs/fhandle.c
56571+++ b/fs/fhandle.c
56572@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
56573 } else
56574 retval = 0;
56575 /* copy the mount id */
56576- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
56577- sizeof(*mnt_id)) ||
56578+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
56579 copy_to_user(ufh, handle,
56580 sizeof(struct file_handle) + handle_bytes))
56581 retval = -EFAULT;
56582diff --git a/fs/file.c b/fs/file.c
56583index 4a78f98..9447397 100644
56584--- a/fs/file.c
56585+++ b/fs/file.c
56586@@ -16,6 +16,7 @@
56587 #include <linux/slab.h>
56588 #include <linux/vmalloc.h>
56589 #include <linux/file.h>
56590+#include <linux/security.h>
56591 #include <linux/fdtable.h>
56592 #include <linux/bitops.h>
56593 #include <linux/interrupt.h>
56594@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
56595 if (!file)
56596 return __close_fd(files, fd);
56597
56598+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
56599 if (fd >= rlimit(RLIMIT_NOFILE))
56600 return -EBADF;
56601
56602@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
56603 if (unlikely(oldfd == newfd))
56604 return -EINVAL;
56605
56606+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
56607 if (newfd >= rlimit(RLIMIT_NOFILE))
56608 return -EBADF;
56609
56610@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
56611 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
56612 {
56613 int err;
56614+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
56615 if (from >= rlimit(RLIMIT_NOFILE))
56616 return -EINVAL;
56617 err = alloc_fd(from, flags);
56618diff --git a/fs/filesystems.c b/fs/filesystems.c
56619index 92567d9..fcd8cbf 100644
56620--- a/fs/filesystems.c
56621+++ b/fs/filesystems.c
56622@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
56623 int len = dot ? dot - name : strlen(name);
56624
56625 fs = __get_fs_type(name, len);
56626+#ifdef CONFIG_GRKERNSEC_MODHARDEN
56627+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
56628+#else
56629 if (!fs && (request_module("fs-%.*s", len, name) == 0))
56630+#endif
56631 fs = __get_fs_type(name, len);
56632
56633 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
56634diff --git a/fs/fs_struct.c b/fs/fs_struct.c
56635index d8ac61d..79a36f0 100644
56636--- a/fs/fs_struct.c
56637+++ b/fs/fs_struct.c
56638@@ -4,6 +4,7 @@
56639 #include <linux/path.h>
56640 #include <linux/slab.h>
56641 #include <linux/fs_struct.h>
56642+#include <linux/grsecurity.h>
56643 #include "internal.h"
56644
56645 /*
56646@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
56647 write_seqcount_begin(&fs->seq);
56648 old_root = fs->root;
56649 fs->root = *path;
56650+ gr_set_chroot_entries(current, path);
56651 write_seqcount_end(&fs->seq);
56652 spin_unlock(&fs->lock);
56653 if (old_root.dentry)
56654@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
56655 int hits = 0;
56656 spin_lock(&fs->lock);
56657 write_seqcount_begin(&fs->seq);
56658+ /* this root replacement is only done by pivot_root,
56659+ leave grsec's chroot tagging alone for this task
56660+ so that a pivoted root isn't treated as a chroot
56661+ */
56662 hits += replace_path(&fs->root, old_root, new_root);
56663 hits += replace_path(&fs->pwd, old_root, new_root);
56664 write_seqcount_end(&fs->seq);
56665@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
56666 task_lock(tsk);
56667 spin_lock(&fs->lock);
56668 tsk->fs = NULL;
56669- kill = !--fs->users;
56670+ gr_clear_chroot_entries(tsk);
56671+ kill = !atomic_dec_return(&fs->users);
56672 spin_unlock(&fs->lock);
56673 task_unlock(tsk);
56674 if (kill)
56675@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56676 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
56677 /* We don't need to lock fs - think why ;-) */
56678 if (fs) {
56679- fs->users = 1;
56680+ atomic_set(&fs->users, 1);
56681 fs->in_exec = 0;
56682 spin_lock_init(&fs->lock);
56683 seqcount_init(&fs->seq);
56684@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56685 spin_lock(&old->lock);
56686 fs->root = old->root;
56687 path_get(&fs->root);
56688+ /* instead of calling gr_set_chroot_entries here,
56689+ we call it from every caller of this function
56690+ */
56691 fs->pwd = old->pwd;
56692 path_get(&fs->pwd);
56693 spin_unlock(&old->lock);
56694@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
56695
56696 task_lock(current);
56697 spin_lock(&fs->lock);
56698- kill = !--fs->users;
56699+ kill = !atomic_dec_return(&fs->users);
56700 current->fs = new_fs;
56701+ gr_set_chroot_entries(current, &new_fs->root);
56702 spin_unlock(&fs->lock);
56703 task_unlock(current);
56704
56705@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
56706
56707 int current_umask(void)
56708 {
56709- return current->fs->umask;
56710+ return current->fs->umask | gr_acl_umask();
56711 }
56712 EXPORT_SYMBOL(current_umask);
56713
56714 /* to be mentioned only in INIT_TASK */
56715 struct fs_struct init_fs = {
56716- .users = 1,
56717+ .users = ATOMIC_INIT(1),
56718 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
56719 .seq = SEQCNT_ZERO,
56720 .umask = 0022,
56721diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
56722index e2cba1f..20319c5 100644
56723--- a/fs/fscache/cookie.c
56724+++ b/fs/fscache/cookie.c
56725@@ -19,7 +19,7 @@
56726
56727 struct kmem_cache *fscache_cookie_jar;
56728
56729-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
56730+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
56731
56732 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
56733 static int fscache_alloc_object(struct fscache_cache *cache,
56734@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
56735 parent ? (char *) parent->def->name : "<no-parent>",
56736 def->name, netfs_data);
56737
56738- fscache_stat(&fscache_n_acquires);
56739+ fscache_stat_unchecked(&fscache_n_acquires);
56740
56741 /* if there's no parent cookie, then we don't create one here either */
56742 if (!parent) {
56743- fscache_stat(&fscache_n_acquires_null);
56744+ fscache_stat_unchecked(&fscache_n_acquires_null);
56745 _leave(" [no parent]");
56746 return NULL;
56747 }
56748@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
56749 /* allocate and initialise a cookie */
56750 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
56751 if (!cookie) {
56752- fscache_stat(&fscache_n_acquires_oom);
56753+ fscache_stat_unchecked(&fscache_n_acquires_oom);
56754 _leave(" [ENOMEM]");
56755 return NULL;
56756 }
56757@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56758
56759 switch (cookie->def->type) {
56760 case FSCACHE_COOKIE_TYPE_INDEX:
56761- fscache_stat(&fscache_n_cookie_index);
56762+ fscache_stat_unchecked(&fscache_n_cookie_index);
56763 break;
56764 case FSCACHE_COOKIE_TYPE_DATAFILE:
56765- fscache_stat(&fscache_n_cookie_data);
56766+ fscache_stat_unchecked(&fscache_n_cookie_data);
56767 break;
56768 default:
56769- fscache_stat(&fscache_n_cookie_special);
56770+ fscache_stat_unchecked(&fscache_n_cookie_special);
56771 break;
56772 }
56773
56774@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56775 if (fscache_acquire_non_index_cookie(cookie) < 0) {
56776 atomic_dec(&parent->n_children);
56777 __fscache_cookie_put(cookie);
56778- fscache_stat(&fscache_n_acquires_nobufs);
56779+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
56780 _leave(" = NULL");
56781 return NULL;
56782 }
56783 }
56784
56785- fscache_stat(&fscache_n_acquires_ok);
56786+ fscache_stat_unchecked(&fscache_n_acquires_ok);
56787 _leave(" = %p", cookie);
56788 return cookie;
56789 }
56790@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
56791 cache = fscache_select_cache_for_object(cookie->parent);
56792 if (!cache) {
56793 up_read(&fscache_addremove_sem);
56794- fscache_stat(&fscache_n_acquires_no_cache);
56795+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
56796 _leave(" = -ENOMEDIUM [no cache]");
56797 return -ENOMEDIUM;
56798 }
56799@@ -255,14 +255,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
56800 object = cache->ops->alloc_object(cache, cookie);
56801 fscache_stat_d(&fscache_n_cop_alloc_object);
56802 if (IS_ERR(object)) {
56803- fscache_stat(&fscache_n_object_no_alloc);
56804+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
56805 ret = PTR_ERR(object);
56806 goto error;
56807 }
56808
56809- fscache_stat(&fscache_n_object_alloc);
56810+ fscache_stat_unchecked(&fscache_n_object_alloc);
56811
56812- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
56813+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
56814
56815 _debug("ALLOC OBJ%x: %s {%lx}",
56816 object->debug_id, cookie->def->name, object->events);
56817@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
56818
56819 _enter("{%s}", cookie->def->name);
56820
56821- fscache_stat(&fscache_n_invalidates);
56822+ fscache_stat_unchecked(&fscache_n_invalidates);
56823
56824 /* Only permit invalidation of data files. Invalidating an index will
56825 * require the caller to release all its attachments to the tree rooted
56826@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
56827 {
56828 struct fscache_object *object;
56829
56830- fscache_stat(&fscache_n_updates);
56831+ fscache_stat_unchecked(&fscache_n_updates);
56832
56833 if (!cookie) {
56834- fscache_stat(&fscache_n_updates_null);
56835+ fscache_stat_unchecked(&fscache_n_updates_null);
56836 _leave(" [no cookie]");
56837 return;
56838 }
56839@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56840 struct fscache_object *object;
56841 unsigned long event;
56842
56843- fscache_stat(&fscache_n_relinquishes);
56844+ fscache_stat_unchecked(&fscache_n_relinquishes);
56845 if (retire)
56846- fscache_stat(&fscache_n_relinquishes_retire);
56847+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
56848
56849 if (!cookie) {
56850- fscache_stat(&fscache_n_relinquishes_null);
56851+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
56852 _leave(" [no cookie]");
56853 return;
56854 }
56855@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56856
56857 /* wait for the cookie to finish being instantiated (or to fail) */
56858 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
56859- fscache_stat(&fscache_n_relinquishes_waitcrt);
56860+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
56861 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
56862 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
56863 }
56864diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
56865index ee38fef..0a326d4 100644
56866--- a/fs/fscache/internal.h
56867+++ b/fs/fscache/internal.h
56868@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
56869 * stats.c
56870 */
56871 #ifdef CONFIG_FSCACHE_STATS
56872-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56873-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56874+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56875+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56876
56877-extern atomic_t fscache_n_op_pend;
56878-extern atomic_t fscache_n_op_run;
56879-extern atomic_t fscache_n_op_enqueue;
56880-extern atomic_t fscache_n_op_deferred_release;
56881-extern atomic_t fscache_n_op_release;
56882-extern atomic_t fscache_n_op_gc;
56883-extern atomic_t fscache_n_op_cancelled;
56884-extern atomic_t fscache_n_op_rejected;
56885+extern atomic_unchecked_t fscache_n_op_pend;
56886+extern atomic_unchecked_t fscache_n_op_run;
56887+extern atomic_unchecked_t fscache_n_op_enqueue;
56888+extern atomic_unchecked_t fscache_n_op_deferred_release;
56889+extern atomic_unchecked_t fscache_n_op_release;
56890+extern atomic_unchecked_t fscache_n_op_gc;
56891+extern atomic_unchecked_t fscache_n_op_cancelled;
56892+extern atomic_unchecked_t fscache_n_op_rejected;
56893
56894-extern atomic_t fscache_n_attr_changed;
56895-extern atomic_t fscache_n_attr_changed_ok;
56896-extern atomic_t fscache_n_attr_changed_nobufs;
56897-extern atomic_t fscache_n_attr_changed_nomem;
56898-extern atomic_t fscache_n_attr_changed_calls;
56899+extern atomic_unchecked_t fscache_n_attr_changed;
56900+extern atomic_unchecked_t fscache_n_attr_changed_ok;
56901+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
56902+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
56903+extern atomic_unchecked_t fscache_n_attr_changed_calls;
56904
56905-extern atomic_t fscache_n_allocs;
56906-extern atomic_t fscache_n_allocs_ok;
56907-extern atomic_t fscache_n_allocs_wait;
56908-extern atomic_t fscache_n_allocs_nobufs;
56909-extern atomic_t fscache_n_allocs_intr;
56910-extern atomic_t fscache_n_allocs_object_dead;
56911-extern atomic_t fscache_n_alloc_ops;
56912-extern atomic_t fscache_n_alloc_op_waits;
56913+extern atomic_unchecked_t fscache_n_allocs;
56914+extern atomic_unchecked_t fscache_n_allocs_ok;
56915+extern atomic_unchecked_t fscache_n_allocs_wait;
56916+extern atomic_unchecked_t fscache_n_allocs_nobufs;
56917+extern atomic_unchecked_t fscache_n_allocs_intr;
56918+extern atomic_unchecked_t fscache_n_allocs_object_dead;
56919+extern atomic_unchecked_t fscache_n_alloc_ops;
56920+extern atomic_unchecked_t fscache_n_alloc_op_waits;
56921
56922-extern atomic_t fscache_n_retrievals;
56923-extern atomic_t fscache_n_retrievals_ok;
56924-extern atomic_t fscache_n_retrievals_wait;
56925-extern atomic_t fscache_n_retrievals_nodata;
56926-extern atomic_t fscache_n_retrievals_nobufs;
56927-extern atomic_t fscache_n_retrievals_intr;
56928-extern atomic_t fscache_n_retrievals_nomem;
56929-extern atomic_t fscache_n_retrievals_object_dead;
56930-extern atomic_t fscache_n_retrieval_ops;
56931-extern atomic_t fscache_n_retrieval_op_waits;
56932+extern atomic_unchecked_t fscache_n_retrievals;
56933+extern atomic_unchecked_t fscache_n_retrievals_ok;
56934+extern atomic_unchecked_t fscache_n_retrievals_wait;
56935+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56936+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56937+extern atomic_unchecked_t fscache_n_retrievals_intr;
56938+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56939+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56940+extern atomic_unchecked_t fscache_n_retrieval_ops;
56941+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56942
56943-extern atomic_t fscache_n_stores;
56944-extern atomic_t fscache_n_stores_ok;
56945-extern atomic_t fscache_n_stores_again;
56946-extern atomic_t fscache_n_stores_nobufs;
56947-extern atomic_t fscache_n_stores_oom;
56948-extern atomic_t fscache_n_store_ops;
56949-extern atomic_t fscache_n_store_calls;
56950-extern atomic_t fscache_n_store_pages;
56951-extern atomic_t fscache_n_store_radix_deletes;
56952-extern atomic_t fscache_n_store_pages_over_limit;
56953+extern atomic_unchecked_t fscache_n_stores;
56954+extern atomic_unchecked_t fscache_n_stores_ok;
56955+extern atomic_unchecked_t fscache_n_stores_again;
56956+extern atomic_unchecked_t fscache_n_stores_nobufs;
56957+extern atomic_unchecked_t fscache_n_stores_oom;
56958+extern atomic_unchecked_t fscache_n_store_ops;
56959+extern atomic_unchecked_t fscache_n_store_calls;
56960+extern atomic_unchecked_t fscache_n_store_pages;
56961+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56962+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56963
56964-extern atomic_t fscache_n_store_vmscan_not_storing;
56965-extern atomic_t fscache_n_store_vmscan_gone;
56966-extern atomic_t fscache_n_store_vmscan_busy;
56967-extern atomic_t fscache_n_store_vmscan_cancelled;
56968-extern atomic_t fscache_n_store_vmscan_wait;
56969+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56970+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56971+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56972+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56973+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56974
56975-extern atomic_t fscache_n_marks;
56976-extern atomic_t fscache_n_uncaches;
56977+extern atomic_unchecked_t fscache_n_marks;
56978+extern atomic_unchecked_t fscache_n_uncaches;
56979
56980-extern atomic_t fscache_n_acquires;
56981-extern atomic_t fscache_n_acquires_null;
56982-extern atomic_t fscache_n_acquires_no_cache;
56983-extern atomic_t fscache_n_acquires_ok;
56984-extern atomic_t fscache_n_acquires_nobufs;
56985-extern atomic_t fscache_n_acquires_oom;
56986+extern atomic_unchecked_t fscache_n_acquires;
56987+extern atomic_unchecked_t fscache_n_acquires_null;
56988+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56989+extern atomic_unchecked_t fscache_n_acquires_ok;
56990+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56991+extern atomic_unchecked_t fscache_n_acquires_oom;
56992
56993-extern atomic_t fscache_n_invalidates;
56994-extern atomic_t fscache_n_invalidates_run;
56995+extern atomic_unchecked_t fscache_n_invalidates;
56996+extern atomic_unchecked_t fscache_n_invalidates_run;
56997
56998-extern atomic_t fscache_n_updates;
56999-extern atomic_t fscache_n_updates_null;
57000-extern atomic_t fscache_n_updates_run;
57001+extern atomic_unchecked_t fscache_n_updates;
57002+extern atomic_unchecked_t fscache_n_updates_null;
57003+extern atomic_unchecked_t fscache_n_updates_run;
57004
57005-extern atomic_t fscache_n_relinquishes;
57006-extern atomic_t fscache_n_relinquishes_null;
57007-extern atomic_t fscache_n_relinquishes_waitcrt;
57008-extern atomic_t fscache_n_relinquishes_retire;
57009+extern atomic_unchecked_t fscache_n_relinquishes;
57010+extern atomic_unchecked_t fscache_n_relinquishes_null;
57011+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57012+extern atomic_unchecked_t fscache_n_relinquishes_retire;
57013
57014-extern atomic_t fscache_n_cookie_index;
57015-extern atomic_t fscache_n_cookie_data;
57016-extern atomic_t fscache_n_cookie_special;
57017+extern atomic_unchecked_t fscache_n_cookie_index;
57018+extern atomic_unchecked_t fscache_n_cookie_data;
57019+extern atomic_unchecked_t fscache_n_cookie_special;
57020
57021-extern atomic_t fscache_n_object_alloc;
57022-extern atomic_t fscache_n_object_no_alloc;
57023-extern atomic_t fscache_n_object_lookups;
57024-extern atomic_t fscache_n_object_lookups_negative;
57025-extern atomic_t fscache_n_object_lookups_positive;
57026-extern atomic_t fscache_n_object_lookups_timed_out;
57027-extern atomic_t fscache_n_object_created;
57028-extern atomic_t fscache_n_object_avail;
57029-extern atomic_t fscache_n_object_dead;
57030+extern atomic_unchecked_t fscache_n_object_alloc;
57031+extern atomic_unchecked_t fscache_n_object_no_alloc;
57032+extern atomic_unchecked_t fscache_n_object_lookups;
57033+extern atomic_unchecked_t fscache_n_object_lookups_negative;
57034+extern atomic_unchecked_t fscache_n_object_lookups_positive;
57035+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
57036+extern atomic_unchecked_t fscache_n_object_created;
57037+extern atomic_unchecked_t fscache_n_object_avail;
57038+extern atomic_unchecked_t fscache_n_object_dead;
57039
57040-extern atomic_t fscache_n_checkaux_none;
57041-extern atomic_t fscache_n_checkaux_okay;
57042-extern atomic_t fscache_n_checkaux_update;
57043-extern atomic_t fscache_n_checkaux_obsolete;
57044+extern atomic_unchecked_t fscache_n_checkaux_none;
57045+extern atomic_unchecked_t fscache_n_checkaux_okay;
57046+extern atomic_unchecked_t fscache_n_checkaux_update;
57047+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
57048
57049 extern atomic_t fscache_n_cop_alloc_object;
57050 extern atomic_t fscache_n_cop_lookup_object;
57051@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
57052 atomic_inc(stat);
57053 }
57054
57055+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
57056+{
57057+ atomic_inc_unchecked(stat);
57058+}
57059+
57060 static inline void fscache_stat_d(atomic_t *stat)
57061 {
57062 atomic_dec(stat);
57063@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
57064
57065 #define __fscache_stat(stat) (NULL)
57066 #define fscache_stat(stat) do {} while (0)
57067+#define fscache_stat_unchecked(stat) do {} while (0)
57068 #define fscache_stat_d(stat) do {} while (0)
57069 #endif
57070
57071diff --git a/fs/fscache/object.c b/fs/fscache/object.c
57072index 50d41c1..10ee117 100644
57073--- a/fs/fscache/object.c
57074+++ b/fs/fscache/object.c
57075@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57076 /* Invalidate an object on disk */
57077 case FSCACHE_OBJECT_INVALIDATING:
57078 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
57079- fscache_stat(&fscache_n_invalidates_run);
57080+ fscache_stat_unchecked(&fscache_n_invalidates_run);
57081 fscache_stat(&fscache_n_cop_invalidate_object);
57082 fscache_invalidate_object(object);
57083 fscache_stat_d(&fscache_n_cop_invalidate_object);
57084@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57085 /* update the object metadata on disk */
57086 case FSCACHE_OBJECT_UPDATING:
57087 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
57088- fscache_stat(&fscache_n_updates_run);
57089+ fscache_stat_unchecked(&fscache_n_updates_run);
57090 fscache_stat(&fscache_n_cop_update_object);
57091 object->cache->ops->update_object(object);
57092 fscache_stat_d(&fscache_n_cop_update_object);
57093@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57094 spin_lock(&object->lock);
57095 object->state = FSCACHE_OBJECT_DEAD;
57096 spin_unlock(&object->lock);
57097- fscache_stat(&fscache_n_object_dead);
57098+ fscache_stat_unchecked(&fscache_n_object_dead);
57099 goto terminal_transit;
57100
57101 /* handle the parent cache of this object being withdrawn from
57102@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
57103 spin_lock(&object->lock);
57104 object->state = FSCACHE_OBJECT_DEAD;
57105 spin_unlock(&object->lock);
57106- fscache_stat(&fscache_n_object_dead);
57107+ fscache_stat_unchecked(&fscache_n_object_dead);
57108 goto terminal_transit;
57109
57110 /* complain about the object being woken up once it is
57111@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
57112 parent->cookie->def->name, cookie->def->name,
57113 object->cache->tag->name);
57114
57115- fscache_stat(&fscache_n_object_lookups);
57116+ fscache_stat_unchecked(&fscache_n_object_lookups);
57117 fscache_stat(&fscache_n_cop_lookup_object);
57118 ret = object->cache->ops->lookup_object(object);
57119 fscache_stat_d(&fscache_n_cop_lookup_object);
57120@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
57121 if (ret == -ETIMEDOUT) {
57122 /* probably stuck behind another object, so move this one to
57123 * the back of the queue */
57124- fscache_stat(&fscache_n_object_lookups_timed_out);
57125+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
57126 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
57127 }
57128
57129@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
57130
57131 spin_lock(&object->lock);
57132 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
57133- fscache_stat(&fscache_n_object_lookups_negative);
57134+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
57135
57136 /* transit here to allow write requests to begin stacking up
57137 * and read requests to begin returning ENODATA */
57138@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
57139 * result, in which case there may be data available */
57140 spin_lock(&object->lock);
57141 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
57142- fscache_stat(&fscache_n_object_lookups_positive);
57143+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
57144
57145 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
57146
57147@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
57148 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
57149 } else {
57150 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
57151- fscache_stat(&fscache_n_object_created);
57152+ fscache_stat_unchecked(&fscache_n_object_created);
57153
57154 object->state = FSCACHE_OBJECT_AVAILABLE;
57155 spin_unlock(&object->lock);
57156@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
57157 fscache_enqueue_dependents(object);
57158
57159 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
57160- fscache_stat(&fscache_n_object_avail);
57161+ fscache_stat_unchecked(&fscache_n_object_avail);
57162
57163 _leave("");
57164 }
57165@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57166 enum fscache_checkaux result;
57167
57168 if (!object->cookie->def->check_aux) {
57169- fscache_stat(&fscache_n_checkaux_none);
57170+ fscache_stat_unchecked(&fscache_n_checkaux_none);
57171 return FSCACHE_CHECKAUX_OKAY;
57172 }
57173
57174@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
57175 switch (result) {
57176 /* entry okay as is */
57177 case FSCACHE_CHECKAUX_OKAY:
57178- fscache_stat(&fscache_n_checkaux_okay);
57179+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
57180 break;
57181
57182 /* entry requires update */
57183 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
57184- fscache_stat(&fscache_n_checkaux_update);
57185+ fscache_stat_unchecked(&fscache_n_checkaux_update);
57186 break;
57187
57188 /* entry requires deletion */
57189 case FSCACHE_CHECKAUX_OBSOLETE:
57190- fscache_stat(&fscache_n_checkaux_obsolete);
57191+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
57192 break;
57193
57194 default:
57195diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
57196index 762a9ec..2023284 100644
57197--- a/fs/fscache/operation.c
57198+++ b/fs/fscache/operation.c
57199@@ -17,7 +17,7 @@
57200 #include <linux/slab.h>
57201 #include "internal.h"
57202
57203-atomic_t fscache_op_debug_id;
57204+atomic_unchecked_t fscache_op_debug_id;
57205 EXPORT_SYMBOL(fscache_op_debug_id);
57206
57207 /**
57208@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
57209 ASSERTCMP(atomic_read(&op->usage), >, 0);
57210 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
57211
57212- fscache_stat(&fscache_n_op_enqueue);
57213+ fscache_stat_unchecked(&fscache_n_op_enqueue);
57214 switch (op->flags & FSCACHE_OP_TYPE) {
57215 case FSCACHE_OP_ASYNC:
57216 _debug("queue async");
57217@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
57218 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
57219 if (op->processor)
57220 fscache_enqueue_operation(op);
57221- fscache_stat(&fscache_n_op_run);
57222+ fscache_stat_unchecked(&fscache_n_op_run);
57223 }
57224
57225 /*
57226@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57227 if (object->n_in_progress > 0) {
57228 atomic_inc(&op->usage);
57229 list_add_tail(&op->pend_link, &object->pending_ops);
57230- fscache_stat(&fscache_n_op_pend);
57231+ fscache_stat_unchecked(&fscache_n_op_pend);
57232 } else if (!list_empty(&object->pending_ops)) {
57233 atomic_inc(&op->usage);
57234 list_add_tail(&op->pend_link, &object->pending_ops);
57235- fscache_stat(&fscache_n_op_pend);
57236+ fscache_stat_unchecked(&fscache_n_op_pend);
57237 fscache_start_operations(object);
57238 } else {
57239 ASSERTCMP(object->n_in_progress, ==, 0);
57240@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
57241 object->n_exclusive++; /* reads and writes must wait */
57242 atomic_inc(&op->usage);
57243 list_add_tail(&op->pend_link, &object->pending_ops);
57244- fscache_stat(&fscache_n_op_pend);
57245+ fscache_stat_unchecked(&fscache_n_op_pend);
57246 ret = 0;
57247 } else {
57248 /* If we're in any other state, there must have been an I/O
57249@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
57250 if (object->n_exclusive > 0) {
57251 atomic_inc(&op->usage);
57252 list_add_tail(&op->pend_link, &object->pending_ops);
57253- fscache_stat(&fscache_n_op_pend);
57254+ fscache_stat_unchecked(&fscache_n_op_pend);
57255 } else if (!list_empty(&object->pending_ops)) {
57256 atomic_inc(&op->usage);
57257 list_add_tail(&op->pend_link, &object->pending_ops);
57258- fscache_stat(&fscache_n_op_pend);
57259+ fscache_stat_unchecked(&fscache_n_op_pend);
57260 fscache_start_operations(object);
57261 } else {
57262 ASSERTCMP(object->n_exclusive, ==, 0);
57263@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
57264 object->n_ops++;
57265 atomic_inc(&op->usage);
57266 list_add_tail(&op->pend_link, &object->pending_ops);
57267- fscache_stat(&fscache_n_op_pend);
57268+ fscache_stat_unchecked(&fscache_n_op_pend);
57269 ret = 0;
57270 } else if (object->state == FSCACHE_OBJECT_DYING ||
57271 object->state == FSCACHE_OBJECT_LC_DYING ||
57272 object->state == FSCACHE_OBJECT_WITHDRAWING) {
57273- fscache_stat(&fscache_n_op_rejected);
57274+ fscache_stat_unchecked(&fscache_n_op_rejected);
57275 op->state = FSCACHE_OP_ST_CANCELLED;
57276 ret = -ENOBUFS;
57277 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
57278@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
57279 ret = -EBUSY;
57280 if (op->state == FSCACHE_OP_ST_PENDING) {
57281 ASSERT(!list_empty(&op->pend_link));
57282- fscache_stat(&fscache_n_op_cancelled);
57283+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57284 list_del_init(&op->pend_link);
57285 if (do_cancel)
57286 do_cancel(op);
57287@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
57288 while (!list_empty(&object->pending_ops)) {
57289 op = list_entry(object->pending_ops.next,
57290 struct fscache_operation, pend_link);
57291- fscache_stat(&fscache_n_op_cancelled);
57292+ fscache_stat_unchecked(&fscache_n_op_cancelled);
57293 list_del_init(&op->pend_link);
57294
57295 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
57296@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
57297 op->state, ==, FSCACHE_OP_ST_CANCELLED);
57298 op->state = FSCACHE_OP_ST_DEAD;
57299
57300- fscache_stat(&fscache_n_op_release);
57301+ fscache_stat_unchecked(&fscache_n_op_release);
57302
57303 if (op->release) {
57304 op->release(op);
57305@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
57306 * lock, and defer it otherwise */
57307 if (!spin_trylock(&object->lock)) {
57308 _debug("defer put");
57309- fscache_stat(&fscache_n_op_deferred_release);
57310+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
57311
57312 cache = object->cache;
57313 spin_lock(&cache->op_gc_list_lock);
57314@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
57315
57316 _debug("GC DEFERRED REL OBJ%x OP%x",
57317 object->debug_id, op->debug_id);
57318- fscache_stat(&fscache_n_op_gc);
57319+ fscache_stat_unchecked(&fscache_n_op_gc);
57320
57321 ASSERTCMP(atomic_read(&op->usage), ==, 0);
57322 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
57323diff --git a/fs/fscache/page.c b/fs/fscache/page.c
57324index ff000e5..c44ec6d 100644
57325--- a/fs/fscache/page.c
57326+++ b/fs/fscache/page.c
57327@@ -61,7 +61,7 @@ try_again:
57328 val = radix_tree_lookup(&cookie->stores, page->index);
57329 if (!val) {
57330 rcu_read_unlock();
57331- fscache_stat(&fscache_n_store_vmscan_not_storing);
57332+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
57333 __fscache_uncache_page(cookie, page);
57334 return true;
57335 }
57336@@ -91,11 +91,11 @@ try_again:
57337 spin_unlock(&cookie->stores_lock);
57338
57339 if (xpage) {
57340- fscache_stat(&fscache_n_store_vmscan_cancelled);
57341- fscache_stat(&fscache_n_store_radix_deletes);
57342+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
57343+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57344 ASSERTCMP(xpage, ==, page);
57345 } else {
57346- fscache_stat(&fscache_n_store_vmscan_gone);
57347+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
57348 }
57349
57350 wake_up_bit(&cookie->flags, 0);
57351@@ -110,11 +110,11 @@ page_busy:
57352 * sleeping on memory allocation, so we may need to impose a timeout
57353 * too. */
57354 if (!(gfp & __GFP_WAIT)) {
57355- fscache_stat(&fscache_n_store_vmscan_busy);
57356+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
57357 return false;
57358 }
57359
57360- fscache_stat(&fscache_n_store_vmscan_wait);
57361+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
57362 __fscache_wait_on_page_write(cookie, page);
57363 gfp &= ~__GFP_WAIT;
57364 goto try_again;
57365@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
57366 FSCACHE_COOKIE_STORING_TAG);
57367 if (!radix_tree_tag_get(&cookie->stores, page->index,
57368 FSCACHE_COOKIE_PENDING_TAG)) {
57369- fscache_stat(&fscache_n_store_radix_deletes);
57370+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
57371 xpage = radix_tree_delete(&cookie->stores, page->index);
57372 }
57373 spin_unlock(&cookie->stores_lock);
57374@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
57375
57376 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
57377
57378- fscache_stat(&fscache_n_attr_changed_calls);
57379+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
57380
57381 if (fscache_object_is_active(object)) {
57382 fscache_stat(&fscache_n_cop_attr_changed);
57383@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57384
57385 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57386
57387- fscache_stat(&fscache_n_attr_changed);
57388+ fscache_stat_unchecked(&fscache_n_attr_changed);
57389
57390 op = kzalloc(sizeof(*op), GFP_KERNEL);
57391 if (!op) {
57392- fscache_stat(&fscache_n_attr_changed_nomem);
57393+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
57394 _leave(" = -ENOMEM");
57395 return -ENOMEM;
57396 }
57397@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57398 if (fscache_submit_exclusive_op(object, op) < 0)
57399 goto nobufs;
57400 spin_unlock(&cookie->lock);
57401- fscache_stat(&fscache_n_attr_changed_ok);
57402+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
57403 fscache_put_operation(op);
57404 _leave(" = 0");
57405 return 0;
57406@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
57407 nobufs:
57408 spin_unlock(&cookie->lock);
57409 kfree(op);
57410- fscache_stat(&fscache_n_attr_changed_nobufs);
57411+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
57412 _leave(" = %d", -ENOBUFS);
57413 return -ENOBUFS;
57414 }
57415@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
57416 /* allocate a retrieval operation and attempt to submit it */
57417 op = kzalloc(sizeof(*op), GFP_NOIO);
57418 if (!op) {
57419- fscache_stat(&fscache_n_retrievals_nomem);
57420+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57421 return NULL;
57422 }
57423
57424@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
57425 return 0;
57426 }
57427
57428- fscache_stat(&fscache_n_retrievals_wait);
57429+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
57430
57431 jif = jiffies;
57432 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
57433 fscache_wait_bit_interruptible,
57434 TASK_INTERRUPTIBLE) != 0) {
57435- fscache_stat(&fscache_n_retrievals_intr);
57436+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57437 _leave(" = -ERESTARTSYS");
57438 return -ERESTARTSYS;
57439 }
57440@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
57441 */
57442 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
57443 struct fscache_retrieval *op,
57444- atomic_t *stat_op_waits,
57445- atomic_t *stat_object_dead)
57446+ atomic_unchecked_t *stat_op_waits,
57447+ atomic_unchecked_t *stat_object_dead)
57448 {
57449 int ret;
57450
57451@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
57452 goto check_if_dead;
57453
57454 _debug(">>> WT");
57455- fscache_stat(stat_op_waits);
57456+ fscache_stat_unchecked(stat_op_waits);
57457 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
57458 fscache_wait_bit_interruptible,
57459 TASK_INTERRUPTIBLE) != 0) {
57460@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
57461
57462 check_if_dead:
57463 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
57464- fscache_stat(stat_object_dead);
57465+ fscache_stat_unchecked(stat_object_dead);
57466 _leave(" = -ENOBUFS [cancelled]");
57467 return -ENOBUFS;
57468 }
57469 if (unlikely(fscache_object_is_dead(object))) {
57470 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
57471 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
57472- fscache_stat(stat_object_dead);
57473+ fscache_stat_unchecked(stat_object_dead);
57474 return -ENOBUFS;
57475 }
57476 return 0;
57477@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57478
57479 _enter("%p,%p,,,", cookie, page);
57480
57481- fscache_stat(&fscache_n_retrievals);
57482+ fscache_stat_unchecked(&fscache_n_retrievals);
57483
57484 if (hlist_empty(&cookie->backing_objects))
57485 goto nobufs;
57486@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57487 goto nobufs_unlock_dec;
57488 spin_unlock(&cookie->lock);
57489
57490- fscache_stat(&fscache_n_retrieval_ops);
57491+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57492
57493 /* pin the netfs read context in case we need to do the actual netfs
57494 * read because we've encountered a cache read failure */
57495@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57496
57497 error:
57498 if (ret == -ENOMEM)
57499- fscache_stat(&fscache_n_retrievals_nomem);
57500+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57501 else if (ret == -ERESTARTSYS)
57502- fscache_stat(&fscache_n_retrievals_intr);
57503+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57504 else if (ret == -ENODATA)
57505- fscache_stat(&fscache_n_retrievals_nodata);
57506+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57507 else if (ret < 0)
57508- fscache_stat(&fscache_n_retrievals_nobufs);
57509+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57510 else
57511- fscache_stat(&fscache_n_retrievals_ok);
57512+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57513
57514 fscache_put_retrieval(op);
57515 _leave(" = %d", ret);
57516@@ -467,7 +467,7 @@ nobufs_unlock:
57517 spin_unlock(&cookie->lock);
57518 kfree(op);
57519 nobufs:
57520- fscache_stat(&fscache_n_retrievals_nobufs);
57521+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57522 _leave(" = -ENOBUFS");
57523 return -ENOBUFS;
57524 }
57525@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57526
57527 _enter("%p,,%d,,,", cookie, *nr_pages);
57528
57529- fscache_stat(&fscache_n_retrievals);
57530+ fscache_stat_unchecked(&fscache_n_retrievals);
57531
57532 if (hlist_empty(&cookie->backing_objects))
57533 goto nobufs;
57534@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57535 goto nobufs_unlock_dec;
57536 spin_unlock(&cookie->lock);
57537
57538- fscache_stat(&fscache_n_retrieval_ops);
57539+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57540
57541 /* pin the netfs read context in case we need to do the actual netfs
57542 * read because we've encountered a cache read failure */
57543@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57544
57545 error:
57546 if (ret == -ENOMEM)
57547- fscache_stat(&fscache_n_retrievals_nomem);
57548+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57549 else if (ret == -ERESTARTSYS)
57550- fscache_stat(&fscache_n_retrievals_intr);
57551+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57552 else if (ret == -ENODATA)
57553- fscache_stat(&fscache_n_retrievals_nodata);
57554+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57555 else if (ret < 0)
57556- fscache_stat(&fscache_n_retrievals_nobufs);
57557+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57558 else
57559- fscache_stat(&fscache_n_retrievals_ok);
57560+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57561
57562 fscache_put_retrieval(op);
57563 _leave(" = %d", ret);
57564@@ -591,7 +591,7 @@ nobufs_unlock:
57565 spin_unlock(&cookie->lock);
57566 kfree(op);
57567 nobufs:
57568- fscache_stat(&fscache_n_retrievals_nobufs);
57569+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57570 _leave(" = -ENOBUFS");
57571 return -ENOBUFS;
57572 }
57573@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57574
57575 _enter("%p,%p,,,", cookie, page);
57576
57577- fscache_stat(&fscache_n_allocs);
57578+ fscache_stat_unchecked(&fscache_n_allocs);
57579
57580 if (hlist_empty(&cookie->backing_objects))
57581 goto nobufs;
57582@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57583 goto nobufs_unlock;
57584 spin_unlock(&cookie->lock);
57585
57586- fscache_stat(&fscache_n_alloc_ops);
57587+ fscache_stat_unchecked(&fscache_n_alloc_ops);
57588
57589 ret = fscache_wait_for_retrieval_activation(
57590 object, op,
57591@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57592
57593 error:
57594 if (ret == -ERESTARTSYS)
57595- fscache_stat(&fscache_n_allocs_intr);
57596+ fscache_stat_unchecked(&fscache_n_allocs_intr);
57597 else if (ret < 0)
57598- fscache_stat(&fscache_n_allocs_nobufs);
57599+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57600 else
57601- fscache_stat(&fscache_n_allocs_ok);
57602+ fscache_stat_unchecked(&fscache_n_allocs_ok);
57603
57604 fscache_put_retrieval(op);
57605 _leave(" = %d", ret);
57606@@ -677,7 +677,7 @@ nobufs_unlock:
57607 spin_unlock(&cookie->lock);
57608 kfree(op);
57609 nobufs:
57610- fscache_stat(&fscache_n_allocs_nobufs);
57611+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57612 _leave(" = -ENOBUFS");
57613 return -ENOBUFS;
57614 }
57615@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57616
57617 spin_lock(&cookie->stores_lock);
57618
57619- fscache_stat(&fscache_n_store_calls);
57620+ fscache_stat_unchecked(&fscache_n_store_calls);
57621
57622 /* find a page to store */
57623 page = NULL;
57624@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57625 page = results[0];
57626 _debug("gang %d [%lx]", n, page->index);
57627 if (page->index > op->store_limit) {
57628- fscache_stat(&fscache_n_store_pages_over_limit);
57629+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
57630 goto superseded;
57631 }
57632
57633@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57634 spin_unlock(&cookie->stores_lock);
57635 spin_unlock(&object->lock);
57636
57637- fscache_stat(&fscache_n_store_pages);
57638+ fscache_stat_unchecked(&fscache_n_store_pages);
57639 fscache_stat(&fscache_n_cop_write_page);
57640 ret = object->cache->ops->write_page(op, page);
57641 fscache_stat_d(&fscache_n_cop_write_page);
57642@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57643 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57644 ASSERT(PageFsCache(page));
57645
57646- fscache_stat(&fscache_n_stores);
57647+ fscache_stat_unchecked(&fscache_n_stores);
57648
57649 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
57650 _leave(" = -ENOBUFS [invalidating]");
57651@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57652 spin_unlock(&cookie->stores_lock);
57653 spin_unlock(&object->lock);
57654
57655- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
57656+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
57657 op->store_limit = object->store_limit;
57658
57659 if (fscache_submit_op(object, &op->op) < 0)
57660@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57661
57662 spin_unlock(&cookie->lock);
57663 radix_tree_preload_end();
57664- fscache_stat(&fscache_n_store_ops);
57665- fscache_stat(&fscache_n_stores_ok);
57666+ fscache_stat_unchecked(&fscache_n_store_ops);
57667+ fscache_stat_unchecked(&fscache_n_stores_ok);
57668
57669 /* the work queue now carries its own ref on the object */
57670 fscache_put_operation(&op->op);
57671@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57672 return 0;
57673
57674 already_queued:
57675- fscache_stat(&fscache_n_stores_again);
57676+ fscache_stat_unchecked(&fscache_n_stores_again);
57677 already_pending:
57678 spin_unlock(&cookie->stores_lock);
57679 spin_unlock(&object->lock);
57680 spin_unlock(&cookie->lock);
57681 radix_tree_preload_end();
57682 kfree(op);
57683- fscache_stat(&fscache_n_stores_ok);
57684+ fscache_stat_unchecked(&fscache_n_stores_ok);
57685 _leave(" = 0");
57686 return 0;
57687
57688@@ -959,14 +959,14 @@ nobufs:
57689 spin_unlock(&cookie->lock);
57690 radix_tree_preload_end();
57691 kfree(op);
57692- fscache_stat(&fscache_n_stores_nobufs);
57693+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
57694 _leave(" = -ENOBUFS");
57695 return -ENOBUFS;
57696
57697 nomem_free:
57698 kfree(op);
57699 nomem:
57700- fscache_stat(&fscache_n_stores_oom);
57701+ fscache_stat_unchecked(&fscache_n_stores_oom);
57702 _leave(" = -ENOMEM");
57703 return -ENOMEM;
57704 }
57705@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
57706 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57707 ASSERTCMP(page, !=, NULL);
57708
57709- fscache_stat(&fscache_n_uncaches);
57710+ fscache_stat_unchecked(&fscache_n_uncaches);
57711
57712 /* cache withdrawal may beat us to it */
57713 if (!PageFsCache(page))
57714@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
57715 struct fscache_cookie *cookie = op->op.object->cookie;
57716
57717 #ifdef CONFIG_FSCACHE_STATS
57718- atomic_inc(&fscache_n_marks);
57719+ atomic_inc_unchecked(&fscache_n_marks);
57720 #endif
57721
57722 _debug("- mark %p{%lx}", page, page->index);
57723diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
57724index 40d13c7..ddf52b9 100644
57725--- a/fs/fscache/stats.c
57726+++ b/fs/fscache/stats.c
57727@@ -18,99 +18,99 @@
57728 /*
57729 * operation counters
57730 */
57731-atomic_t fscache_n_op_pend;
57732-atomic_t fscache_n_op_run;
57733-atomic_t fscache_n_op_enqueue;
57734-atomic_t fscache_n_op_requeue;
57735-atomic_t fscache_n_op_deferred_release;
57736-atomic_t fscache_n_op_release;
57737-atomic_t fscache_n_op_gc;
57738-atomic_t fscache_n_op_cancelled;
57739-atomic_t fscache_n_op_rejected;
57740+atomic_unchecked_t fscache_n_op_pend;
57741+atomic_unchecked_t fscache_n_op_run;
57742+atomic_unchecked_t fscache_n_op_enqueue;
57743+atomic_unchecked_t fscache_n_op_requeue;
57744+atomic_unchecked_t fscache_n_op_deferred_release;
57745+atomic_unchecked_t fscache_n_op_release;
57746+atomic_unchecked_t fscache_n_op_gc;
57747+atomic_unchecked_t fscache_n_op_cancelled;
57748+atomic_unchecked_t fscache_n_op_rejected;
57749
57750-atomic_t fscache_n_attr_changed;
57751-atomic_t fscache_n_attr_changed_ok;
57752-atomic_t fscache_n_attr_changed_nobufs;
57753-atomic_t fscache_n_attr_changed_nomem;
57754-atomic_t fscache_n_attr_changed_calls;
57755+atomic_unchecked_t fscache_n_attr_changed;
57756+atomic_unchecked_t fscache_n_attr_changed_ok;
57757+atomic_unchecked_t fscache_n_attr_changed_nobufs;
57758+atomic_unchecked_t fscache_n_attr_changed_nomem;
57759+atomic_unchecked_t fscache_n_attr_changed_calls;
57760
57761-atomic_t fscache_n_allocs;
57762-atomic_t fscache_n_allocs_ok;
57763-atomic_t fscache_n_allocs_wait;
57764-atomic_t fscache_n_allocs_nobufs;
57765-atomic_t fscache_n_allocs_intr;
57766-atomic_t fscache_n_allocs_object_dead;
57767-atomic_t fscache_n_alloc_ops;
57768-atomic_t fscache_n_alloc_op_waits;
57769+atomic_unchecked_t fscache_n_allocs;
57770+atomic_unchecked_t fscache_n_allocs_ok;
57771+atomic_unchecked_t fscache_n_allocs_wait;
57772+atomic_unchecked_t fscache_n_allocs_nobufs;
57773+atomic_unchecked_t fscache_n_allocs_intr;
57774+atomic_unchecked_t fscache_n_allocs_object_dead;
57775+atomic_unchecked_t fscache_n_alloc_ops;
57776+atomic_unchecked_t fscache_n_alloc_op_waits;
57777
57778-atomic_t fscache_n_retrievals;
57779-atomic_t fscache_n_retrievals_ok;
57780-atomic_t fscache_n_retrievals_wait;
57781-atomic_t fscache_n_retrievals_nodata;
57782-atomic_t fscache_n_retrievals_nobufs;
57783-atomic_t fscache_n_retrievals_intr;
57784-atomic_t fscache_n_retrievals_nomem;
57785-atomic_t fscache_n_retrievals_object_dead;
57786-atomic_t fscache_n_retrieval_ops;
57787-atomic_t fscache_n_retrieval_op_waits;
57788+atomic_unchecked_t fscache_n_retrievals;
57789+atomic_unchecked_t fscache_n_retrievals_ok;
57790+atomic_unchecked_t fscache_n_retrievals_wait;
57791+atomic_unchecked_t fscache_n_retrievals_nodata;
57792+atomic_unchecked_t fscache_n_retrievals_nobufs;
57793+atomic_unchecked_t fscache_n_retrievals_intr;
57794+atomic_unchecked_t fscache_n_retrievals_nomem;
57795+atomic_unchecked_t fscache_n_retrievals_object_dead;
57796+atomic_unchecked_t fscache_n_retrieval_ops;
57797+atomic_unchecked_t fscache_n_retrieval_op_waits;
57798
57799-atomic_t fscache_n_stores;
57800-atomic_t fscache_n_stores_ok;
57801-atomic_t fscache_n_stores_again;
57802-atomic_t fscache_n_stores_nobufs;
57803-atomic_t fscache_n_stores_oom;
57804-atomic_t fscache_n_store_ops;
57805-atomic_t fscache_n_store_calls;
57806-atomic_t fscache_n_store_pages;
57807-atomic_t fscache_n_store_radix_deletes;
57808-atomic_t fscache_n_store_pages_over_limit;
57809+atomic_unchecked_t fscache_n_stores;
57810+atomic_unchecked_t fscache_n_stores_ok;
57811+atomic_unchecked_t fscache_n_stores_again;
57812+atomic_unchecked_t fscache_n_stores_nobufs;
57813+atomic_unchecked_t fscache_n_stores_oom;
57814+atomic_unchecked_t fscache_n_store_ops;
57815+atomic_unchecked_t fscache_n_store_calls;
57816+atomic_unchecked_t fscache_n_store_pages;
57817+atomic_unchecked_t fscache_n_store_radix_deletes;
57818+atomic_unchecked_t fscache_n_store_pages_over_limit;
57819
57820-atomic_t fscache_n_store_vmscan_not_storing;
57821-atomic_t fscache_n_store_vmscan_gone;
57822-atomic_t fscache_n_store_vmscan_busy;
57823-atomic_t fscache_n_store_vmscan_cancelled;
57824-atomic_t fscache_n_store_vmscan_wait;
57825+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57826+atomic_unchecked_t fscache_n_store_vmscan_gone;
57827+atomic_unchecked_t fscache_n_store_vmscan_busy;
57828+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57829+atomic_unchecked_t fscache_n_store_vmscan_wait;
57830
57831-atomic_t fscache_n_marks;
57832-atomic_t fscache_n_uncaches;
57833+atomic_unchecked_t fscache_n_marks;
57834+atomic_unchecked_t fscache_n_uncaches;
57835
57836-atomic_t fscache_n_acquires;
57837-atomic_t fscache_n_acquires_null;
57838-atomic_t fscache_n_acquires_no_cache;
57839-atomic_t fscache_n_acquires_ok;
57840-atomic_t fscache_n_acquires_nobufs;
57841-atomic_t fscache_n_acquires_oom;
57842+atomic_unchecked_t fscache_n_acquires;
57843+atomic_unchecked_t fscache_n_acquires_null;
57844+atomic_unchecked_t fscache_n_acquires_no_cache;
57845+atomic_unchecked_t fscache_n_acquires_ok;
57846+atomic_unchecked_t fscache_n_acquires_nobufs;
57847+atomic_unchecked_t fscache_n_acquires_oom;
57848
57849-atomic_t fscache_n_invalidates;
57850-atomic_t fscache_n_invalidates_run;
57851+atomic_unchecked_t fscache_n_invalidates;
57852+atomic_unchecked_t fscache_n_invalidates_run;
57853
57854-atomic_t fscache_n_updates;
57855-atomic_t fscache_n_updates_null;
57856-atomic_t fscache_n_updates_run;
57857+atomic_unchecked_t fscache_n_updates;
57858+atomic_unchecked_t fscache_n_updates_null;
57859+atomic_unchecked_t fscache_n_updates_run;
57860
57861-atomic_t fscache_n_relinquishes;
57862-atomic_t fscache_n_relinquishes_null;
57863-atomic_t fscache_n_relinquishes_waitcrt;
57864-atomic_t fscache_n_relinquishes_retire;
57865+atomic_unchecked_t fscache_n_relinquishes;
57866+atomic_unchecked_t fscache_n_relinquishes_null;
57867+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57868+atomic_unchecked_t fscache_n_relinquishes_retire;
57869
57870-atomic_t fscache_n_cookie_index;
57871-atomic_t fscache_n_cookie_data;
57872-atomic_t fscache_n_cookie_special;
57873+atomic_unchecked_t fscache_n_cookie_index;
57874+atomic_unchecked_t fscache_n_cookie_data;
57875+atomic_unchecked_t fscache_n_cookie_special;
57876
57877-atomic_t fscache_n_object_alloc;
57878-atomic_t fscache_n_object_no_alloc;
57879-atomic_t fscache_n_object_lookups;
57880-atomic_t fscache_n_object_lookups_negative;
57881-atomic_t fscache_n_object_lookups_positive;
57882-atomic_t fscache_n_object_lookups_timed_out;
57883-atomic_t fscache_n_object_created;
57884-atomic_t fscache_n_object_avail;
57885-atomic_t fscache_n_object_dead;
57886+atomic_unchecked_t fscache_n_object_alloc;
57887+atomic_unchecked_t fscache_n_object_no_alloc;
57888+atomic_unchecked_t fscache_n_object_lookups;
57889+atomic_unchecked_t fscache_n_object_lookups_negative;
57890+atomic_unchecked_t fscache_n_object_lookups_positive;
57891+atomic_unchecked_t fscache_n_object_lookups_timed_out;
57892+atomic_unchecked_t fscache_n_object_created;
57893+atomic_unchecked_t fscache_n_object_avail;
57894+atomic_unchecked_t fscache_n_object_dead;
57895
57896-atomic_t fscache_n_checkaux_none;
57897-atomic_t fscache_n_checkaux_okay;
57898-atomic_t fscache_n_checkaux_update;
57899-atomic_t fscache_n_checkaux_obsolete;
57900+atomic_unchecked_t fscache_n_checkaux_none;
57901+atomic_unchecked_t fscache_n_checkaux_okay;
57902+atomic_unchecked_t fscache_n_checkaux_update;
57903+atomic_unchecked_t fscache_n_checkaux_obsolete;
57904
57905 atomic_t fscache_n_cop_alloc_object;
57906 atomic_t fscache_n_cop_lookup_object;
57907@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
57908 seq_puts(m, "FS-Cache statistics\n");
57909
57910 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
57911- atomic_read(&fscache_n_cookie_index),
57912- atomic_read(&fscache_n_cookie_data),
57913- atomic_read(&fscache_n_cookie_special));
57914+ atomic_read_unchecked(&fscache_n_cookie_index),
57915+ atomic_read_unchecked(&fscache_n_cookie_data),
57916+ atomic_read_unchecked(&fscache_n_cookie_special));
57917
57918 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
57919- atomic_read(&fscache_n_object_alloc),
57920- atomic_read(&fscache_n_object_no_alloc),
57921- atomic_read(&fscache_n_object_avail),
57922- atomic_read(&fscache_n_object_dead));
57923+ atomic_read_unchecked(&fscache_n_object_alloc),
57924+ atomic_read_unchecked(&fscache_n_object_no_alloc),
57925+ atomic_read_unchecked(&fscache_n_object_avail),
57926+ atomic_read_unchecked(&fscache_n_object_dead));
57927 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
57928- atomic_read(&fscache_n_checkaux_none),
57929- atomic_read(&fscache_n_checkaux_okay),
57930- atomic_read(&fscache_n_checkaux_update),
57931- atomic_read(&fscache_n_checkaux_obsolete));
57932+ atomic_read_unchecked(&fscache_n_checkaux_none),
57933+ atomic_read_unchecked(&fscache_n_checkaux_okay),
57934+ atomic_read_unchecked(&fscache_n_checkaux_update),
57935+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57936
57937 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57938- atomic_read(&fscache_n_marks),
57939- atomic_read(&fscache_n_uncaches));
57940+ atomic_read_unchecked(&fscache_n_marks),
57941+ atomic_read_unchecked(&fscache_n_uncaches));
57942
57943 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57944 " oom=%u\n",
57945- atomic_read(&fscache_n_acquires),
57946- atomic_read(&fscache_n_acquires_null),
57947- atomic_read(&fscache_n_acquires_no_cache),
57948- atomic_read(&fscache_n_acquires_ok),
57949- atomic_read(&fscache_n_acquires_nobufs),
57950- atomic_read(&fscache_n_acquires_oom));
57951+ atomic_read_unchecked(&fscache_n_acquires),
57952+ atomic_read_unchecked(&fscache_n_acquires_null),
57953+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57954+ atomic_read_unchecked(&fscache_n_acquires_ok),
57955+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57956+ atomic_read_unchecked(&fscache_n_acquires_oom));
57957
57958 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57959- atomic_read(&fscache_n_object_lookups),
57960- atomic_read(&fscache_n_object_lookups_negative),
57961- atomic_read(&fscache_n_object_lookups_positive),
57962- atomic_read(&fscache_n_object_created),
57963- atomic_read(&fscache_n_object_lookups_timed_out));
57964+ atomic_read_unchecked(&fscache_n_object_lookups),
57965+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57966+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57967+ atomic_read_unchecked(&fscache_n_object_created),
57968+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57969
57970 seq_printf(m, "Invals : n=%u run=%u\n",
57971- atomic_read(&fscache_n_invalidates),
57972- atomic_read(&fscache_n_invalidates_run));
57973+ atomic_read_unchecked(&fscache_n_invalidates),
57974+ atomic_read_unchecked(&fscache_n_invalidates_run));
57975
57976 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57977- atomic_read(&fscache_n_updates),
57978- atomic_read(&fscache_n_updates_null),
57979- atomic_read(&fscache_n_updates_run));
57980+ atomic_read_unchecked(&fscache_n_updates),
57981+ atomic_read_unchecked(&fscache_n_updates_null),
57982+ atomic_read_unchecked(&fscache_n_updates_run));
57983
57984 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57985- atomic_read(&fscache_n_relinquishes),
57986- atomic_read(&fscache_n_relinquishes_null),
57987- atomic_read(&fscache_n_relinquishes_waitcrt),
57988- atomic_read(&fscache_n_relinquishes_retire));
57989+ atomic_read_unchecked(&fscache_n_relinquishes),
57990+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57991+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57992+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57993
57994 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57995- atomic_read(&fscache_n_attr_changed),
57996- atomic_read(&fscache_n_attr_changed_ok),
57997- atomic_read(&fscache_n_attr_changed_nobufs),
57998- atomic_read(&fscache_n_attr_changed_nomem),
57999- atomic_read(&fscache_n_attr_changed_calls));
58000+ atomic_read_unchecked(&fscache_n_attr_changed),
58001+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
58002+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
58003+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
58004+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
58005
58006 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
58007- atomic_read(&fscache_n_allocs),
58008- atomic_read(&fscache_n_allocs_ok),
58009- atomic_read(&fscache_n_allocs_wait),
58010- atomic_read(&fscache_n_allocs_nobufs),
58011- atomic_read(&fscache_n_allocs_intr));
58012+ atomic_read_unchecked(&fscache_n_allocs),
58013+ atomic_read_unchecked(&fscache_n_allocs_ok),
58014+ atomic_read_unchecked(&fscache_n_allocs_wait),
58015+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
58016+ atomic_read_unchecked(&fscache_n_allocs_intr));
58017 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
58018- atomic_read(&fscache_n_alloc_ops),
58019- atomic_read(&fscache_n_alloc_op_waits),
58020- atomic_read(&fscache_n_allocs_object_dead));
58021+ atomic_read_unchecked(&fscache_n_alloc_ops),
58022+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
58023+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
58024
58025 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
58026 " int=%u oom=%u\n",
58027- atomic_read(&fscache_n_retrievals),
58028- atomic_read(&fscache_n_retrievals_ok),
58029- atomic_read(&fscache_n_retrievals_wait),
58030- atomic_read(&fscache_n_retrievals_nodata),
58031- atomic_read(&fscache_n_retrievals_nobufs),
58032- atomic_read(&fscache_n_retrievals_intr),
58033- atomic_read(&fscache_n_retrievals_nomem));
58034+ atomic_read_unchecked(&fscache_n_retrievals),
58035+ atomic_read_unchecked(&fscache_n_retrievals_ok),
58036+ atomic_read_unchecked(&fscache_n_retrievals_wait),
58037+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
58038+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
58039+ atomic_read_unchecked(&fscache_n_retrievals_intr),
58040+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
58041 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
58042- atomic_read(&fscache_n_retrieval_ops),
58043- atomic_read(&fscache_n_retrieval_op_waits),
58044- atomic_read(&fscache_n_retrievals_object_dead));
58045+ atomic_read_unchecked(&fscache_n_retrieval_ops),
58046+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
58047+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
58048
58049 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
58050- atomic_read(&fscache_n_stores),
58051- atomic_read(&fscache_n_stores_ok),
58052- atomic_read(&fscache_n_stores_again),
58053- atomic_read(&fscache_n_stores_nobufs),
58054- atomic_read(&fscache_n_stores_oom));
58055+ atomic_read_unchecked(&fscache_n_stores),
58056+ atomic_read_unchecked(&fscache_n_stores_ok),
58057+ atomic_read_unchecked(&fscache_n_stores_again),
58058+ atomic_read_unchecked(&fscache_n_stores_nobufs),
58059+ atomic_read_unchecked(&fscache_n_stores_oom));
58060 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
58061- atomic_read(&fscache_n_store_ops),
58062- atomic_read(&fscache_n_store_calls),
58063- atomic_read(&fscache_n_store_pages),
58064- atomic_read(&fscache_n_store_radix_deletes),
58065- atomic_read(&fscache_n_store_pages_over_limit));
58066+ atomic_read_unchecked(&fscache_n_store_ops),
58067+ atomic_read_unchecked(&fscache_n_store_calls),
58068+ atomic_read_unchecked(&fscache_n_store_pages),
58069+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
58070+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
58071
58072 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
58073- atomic_read(&fscache_n_store_vmscan_not_storing),
58074- atomic_read(&fscache_n_store_vmscan_gone),
58075- atomic_read(&fscache_n_store_vmscan_busy),
58076- atomic_read(&fscache_n_store_vmscan_cancelled),
58077- atomic_read(&fscache_n_store_vmscan_wait));
58078+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
58079+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
58080+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
58081+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
58082+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
58083
58084 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
58085- atomic_read(&fscache_n_op_pend),
58086- atomic_read(&fscache_n_op_run),
58087- atomic_read(&fscache_n_op_enqueue),
58088- atomic_read(&fscache_n_op_cancelled),
58089- atomic_read(&fscache_n_op_rejected));
58090+ atomic_read_unchecked(&fscache_n_op_pend),
58091+ atomic_read_unchecked(&fscache_n_op_run),
58092+ atomic_read_unchecked(&fscache_n_op_enqueue),
58093+ atomic_read_unchecked(&fscache_n_op_cancelled),
58094+ atomic_read_unchecked(&fscache_n_op_rejected));
58095 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
58096- atomic_read(&fscache_n_op_deferred_release),
58097- atomic_read(&fscache_n_op_release),
58098- atomic_read(&fscache_n_op_gc));
58099+ atomic_read_unchecked(&fscache_n_op_deferred_release),
58100+ atomic_read_unchecked(&fscache_n_op_release),
58101+ atomic_read_unchecked(&fscache_n_op_gc));
58102
58103 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
58104 atomic_read(&fscache_n_cop_alloc_object),
58105diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
58106index aef34b1..59bfd7b 100644
58107--- a/fs/fuse/cuse.c
58108+++ b/fs/fuse/cuse.c
58109@@ -600,10 +600,12 @@ static int __init cuse_init(void)
58110 INIT_LIST_HEAD(&cuse_conntbl[i]);
58111
58112 /* inherit and extend fuse_dev_operations */
58113- cuse_channel_fops = fuse_dev_operations;
58114- cuse_channel_fops.owner = THIS_MODULE;
58115- cuse_channel_fops.open = cuse_channel_open;
58116- cuse_channel_fops.release = cuse_channel_release;
58117+ pax_open_kernel();
58118+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
58119+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
58120+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
58121+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
58122+ pax_close_kernel();
58123
58124 cuse_class = class_create(THIS_MODULE, "cuse");
58125 if (IS_ERR(cuse_class))
58126diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
58127index 1d55f94..088da65 100644
58128--- a/fs/fuse/dev.c
58129+++ b/fs/fuse/dev.c
58130@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58131 ret = 0;
58132 pipe_lock(pipe);
58133
58134- if (!pipe->readers) {
58135+ if (!atomic_read(&pipe->readers)) {
58136 send_sig(SIGPIPE, current, 0);
58137 if (!ret)
58138 ret = -EPIPE;
58139@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
58140 page_nr++;
58141 ret += buf->len;
58142
58143- if (pipe->files)
58144+ if (atomic_read(&pipe->files))
58145 do_wakeup = 1;
58146 }
58147
58148diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
58149index 5b12746..b481b03 100644
58150--- a/fs/fuse/dir.c
58151+++ b/fs/fuse/dir.c
58152@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
58153 return link;
58154 }
58155
58156-static void free_link(char *link)
58157+static void free_link(const char *link)
58158 {
58159 if (!IS_ERR(link))
58160 free_page((unsigned long) link);
58161diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
58162index 62b484e..0f9a140 100644
58163--- a/fs/gfs2/inode.c
58164+++ b/fs/gfs2/inode.c
58165@@ -1441,7 +1441,7 @@ out:
58166
58167 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58168 {
58169- char *s = nd_get_link(nd);
58170+ const char *s = nd_get_link(nd);
58171 if (!IS_ERR(s))
58172 kfree(s);
58173 }
58174diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
58175index a3f868a..bb308ae 100644
58176--- a/fs/hugetlbfs/inode.c
58177+++ b/fs/hugetlbfs/inode.c
58178@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58179 struct mm_struct *mm = current->mm;
58180 struct vm_area_struct *vma;
58181 struct hstate *h = hstate_file(file);
58182+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
58183 struct vm_unmapped_area_info info;
58184
58185 if (len & ~huge_page_mask(h))
58186@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
58187 return addr;
58188 }
58189
58190+#ifdef CONFIG_PAX_RANDMMAP
58191+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
58192+#endif
58193+
58194 if (addr) {
58195 addr = ALIGN(addr, huge_page_size(h));
58196 vma = find_vma(mm, addr);
58197- if (TASK_SIZE - len >= addr &&
58198- (!vma || addr + len <= vma->vm_start))
58199+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
58200 return addr;
58201 }
58202
58203 info.flags = 0;
58204 info.length = len;
58205 info.low_limit = TASK_UNMAPPED_BASE;
58206+
58207+#ifdef CONFIG_PAX_RANDMMAP
58208+ if (mm->pax_flags & MF_PAX_RANDMMAP)
58209+ info.low_limit += mm->delta_mmap;
58210+#endif
58211+
58212 info.high_limit = TASK_SIZE;
58213 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
58214 info.align_offset = 0;
58215@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
58216 };
58217 MODULE_ALIAS_FS("hugetlbfs");
58218
58219-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58220+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58221
58222 static int can_do_hugetlb_shm(void)
58223 {
58224diff --git a/fs/inode.c b/fs/inode.c
58225index 00d5fc3..98ce7d7 100644
58226--- a/fs/inode.c
58227+++ b/fs/inode.c
58228@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
58229
58230 #ifdef CONFIG_SMP
58231 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
58232- static atomic_t shared_last_ino;
58233- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
58234+ static atomic_unchecked_t shared_last_ino;
58235+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
58236
58237 res = next - LAST_INO_BATCH;
58238 }
58239diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
58240index 4a6cf28..d3a29d3 100644
58241--- a/fs/jffs2/erase.c
58242+++ b/fs/jffs2/erase.c
58243@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
58244 struct jffs2_unknown_node marker = {
58245 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
58246 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58247- .totlen = cpu_to_je32(c->cleanmarker_size)
58248+ .totlen = cpu_to_je32(c->cleanmarker_size),
58249+ .hdr_crc = cpu_to_je32(0)
58250 };
58251
58252 jffs2_prealloc_raw_node_refs(c, jeb, 1);
58253diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
58254index a6597d6..41b30ec 100644
58255--- a/fs/jffs2/wbuf.c
58256+++ b/fs/jffs2/wbuf.c
58257@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
58258 {
58259 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
58260 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
58261- .totlen = constant_cpu_to_je32(8)
58262+ .totlen = constant_cpu_to_je32(8),
58263+ .hdr_crc = constant_cpu_to_je32(0)
58264 };
58265
58266 /*
58267diff --git a/fs/jfs/super.c b/fs/jfs/super.c
58268index 788e0a9..8433098 100644
58269--- a/fs/jfs/super.c
58270+++ b/fs/jfs/super.c
58271@@ -878,7 +878,7 @@ static int __init init_jfs_fs(void)
58272
58273 jfs_inode_cachep =
58274 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
58275- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
58276+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
58277 init_once);
58278 if (jfs_inode_cachep == NULL)
58279 return -ENOMEM;
58280diff --git a/fs/libfs.c b/fs/libfs.c
58281index 916da8c..1588998 100644
58282--- a/fs/libfs.c
58283+++ b/fs/libfs.c
58284@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
58285
58286 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
58287 struct dentry *next;
58288+ char d_name[sizeof(next->d_iname)];
58289+ const unsigned char *name;
58290+
58291 next = list_entry(p, struct dentry, d_u.d_child);
58292 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
58293 if (!simple_positive(next)) {
58294@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
58295
58296 spin_unlock(&next->d_lock);
58297 spin_unlock(&dentry->d_lock);
58298- if (filldir(dirent, next->d_name.name,
58299+ name = next->d_name.name;
58300+ if (name == next->d_iname) {
58301+ memcpy(d_name, name, next->d_name.len);
58302+ name = d_name;
58303+ }
58304+ if (filldir(dirent, name,
58305 next->d_name.len, filp->f_pos,
58306 next->d_inode->i_ino,
58307 dt_type(next->d_inode)) < 0)
58308diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
58309index acd3947..1f896e2 100644
58310--- a/fs/lockd/clntproc.c
58311+++ b/fs/lockd/clntproc.c
58312@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
58313 /*
58314 * Cookie counter for NLM requests
58315 */
58316-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
58317+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
58318
58319 void nlmclnt_next_cookie(struct nlm_cookie *c)
58320 {
58321- u32 cookie = atomic_inc_return(&nlm_cookie);
58322+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
58323
58324 memcpy(c->data, &cookie, 4);
58325 c->len=4;
58326diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
58327index a2aa97d..10d6c41 100644
58328--- a/fs/lockd/svc.c
58329+++ b/fs/lockd/svc.c
58330@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
58331 svc_sock_update_bufs(serv);
58332 serv->sv_maxconn = nlm_max_connections;
58333
58334- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
58335+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
58336 if (IS_ERR(nlmsvc_task)) {
58337 error = PTR_ERR(nlmsvc_task);
58338 printk(KERN_WARNING
58339diff --git a/fs/locks.c b/fs/locks.c
58340index cb424a4..850e4dd 100644
58341--- a/fs/locks.c
58342+++ b/fs/locks.c
58343@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
58344 return;
58345
58346 if (filp->f_op && filp->f_op->flock) {
58347- struct file_lock fl = {
58348+ struct file_lock flock = {
58349 .fl_pid = current->tgid,
58350 .fl_file = filp,
58351 .fl_flags = FL_FLOCK,
58352 .fl_type = F_UNLCK,
58353 .fl_end = OFFSET_MAX,
58354 };
58355- filp->f_op->flock(filp, F_SETLKW, &fl);
58356- if (fl.fl_ops && fl.fl_ops->fl_release_private)
58357- fl.fl_ops->fl_release_private(&fl);
58358+ filp->f_op->flock(filp, F_SETLKW, &flock);
58359+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
58360+ flock.fl_ops->fl_release_private(&flock);
58361 }
58362
58363 lock_flocks();
58364diff --git a/fs/namei.c b/fs/namei.c
58365index 9ed9361..2b72db1 100644
58366--- a/fs/namei.c
58367+++ b/fs/namei.c
58368@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
58369 if (ret != -EACCES)
58370 return ret;
58371
58372+#ifdef CONFIG_GRKERNSEC
58373+ /* we'll block if we have to log due to a denied capability use */
58374+ if (mask & MAY_NOT_BLOCK)
58375+ return -ECHILD;
58376+#endif
58377+
58378 if (S_ISDIR(inode->i_mode)) {
58379 /* DACs are overridable for directories */
58380- if (inode_capable(inode, CAP_DAC_OVERRIDE))
58381- return 0;
58382 if (!(mask & MAY_WRITE))
58383- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58384+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58385+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58386 return 0;
58387+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
58388+ return 0;
58389 return -EACCES;
58390 }
58391 /*
58392+ * Searching includes executable on directories, else just read.
58393+ */
58394+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58395+ if (mask == MAY_READ)
58396+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
58397+ inode_capable(inode, CAP_DAC_READ_SEARCH))
58398+ return 0;
58399+
58400+ /*
58401 * Read/write DACs are always overridable.
58402 * Executable DACs are overridable when there is
58403 * at least one exec bit set.
58404@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
58405 if (inode_capable(inode, CAP_DAC_OVERRIDE))
58406 return 0;
58407
58408- /*
58409- * Searching includes executable on directories, else just read.
58410- */
58411- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
58412- if (mask == MAY_READ)
58413- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
58414- return 0;
58415-
58416 return -EACCES;
58417 }
58418
58419@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58420 {
58421 struct dentry *dentry = link->dentry;
58422 int error;
58423- char *s;
58424+ const char *s;
58425
58426 BUG_ON(nd->flags & LOOKUP_RCU);
58427
58428@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
58429 if (error)
58430 goto out_put_nd_path;
58431
58432+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
58433+ dentry->d_inode, dentry, nd->path.mnt)) {
58434+ error = -EACCES;
58435+ goto out_put_nd_path;
58436+ }
58437+
58438 nd->last_type = LAST_BIND;
58439 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
58440 error = PTR_ERR(*p);
58441@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
58442 if (res)
58443 break;
58444 res = walk_component(nd, path, LOOKUP_FOLLOW);
58445+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
58446+ res = -EACCES;
58447 put_link(nd, &link, cookie);
58448 } while (res > 0);
58449
58450@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
58451 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
58452 {
58453 unsigned long a, b, adata, bdata, mask, hash, len;
58454- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58455+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58456
58457 hash = a = 0;
58458 len = -sizeof(unsigned long);
58459@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
58460 if (err)
58461 break;
58462 err = lookup_last(nd, &path);
58463+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
58464+ err = -EACCES;
58465 put_link(nd, &link, cookie);
58466 }
58467 }
58468@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
58469 if (!err)
58470 err = complete_walk(nd);
58471
58472+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
58473+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58474+ path_put(&nd->path);
58475+ err = -ENOENT;
58476+ }
58477+ }
58478+
58479 if (!err && nd->flags & LOOKUP_DIRECTORY) {
58480 if (!can_lookup(nd->inode)) {
58481 path_put(&nd->path);
58482@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
58483 retval = path_lookupat(dfd, name->name,
58484 flags | LOOKUP_REVAL, nd);
58485
58486- if (likely(!retval))
58487+ if (likely(!retval)) {
58488 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
58489+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
58490+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
58491+ path_put(&nd->path);
58492+ return -ENOENT;
58493+ }
58494+ }
58495+ }
58496 return retval;
58497 }
58498
58499@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
58500 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
58501 return -EPERM;
58502
58503+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
58504+ return -EPERM;
58505+ if (gr_handle_rawio(inode))
58506+ return -EPERM;
58507+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
58508+ return -EACCES;
58509+
58510 return 0;
58511 }
58512
58513@@ -2602,7 +2641,7 @@ looked_up:
58514 * cleared otherwise prior to returning.
58515 */
58516 static int lookup_open(struct nameidata *nd, struct path *path,
58517- struct file *file,
58518+ struct path *link, struct file *file,
58519 const struct open_flags *op,
58520 bool got_write, int *opened)
58521 {
58522@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58523 /* Negative dentry, just create the file */
58524 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
58525 umode_t mode = op->mode;
58526+
58527+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
58528+ error = -EACCES;
58529+ goto out_dput;
58530+ }
58531+
58532+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
58533+ error = -EACCES;
58534+ goto out_dput;
58535+ }
58536+
58537 if (!IS_POSIXACL(dir->d_inode))
58538 mode &= ~current_umask();
58539 /*
58540@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58541 nd->flags & LOOKUP_EXCL);
58542 if (error)
58543 goto out_dput;
58544+ else
58545+ gr_handle_create(dentry, nd->path.mnt);
58546 }
58547 out_no_open:
58548 path->dentry = dentry;
58549@@ -2672,7 +2724,7 @@ out_dput:
58550 /*
58551 * Handle the last step of open()
58552 */
58553-static int do_last(struct nameidata *nd, struct path *path,
58554+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
58555 struct file *file, const struct open_flags *op,
58556 int *opened, struct filename *name)
58557 {
58558@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
58559 error = complete_walk(nd);
58560 if (error)
58561 return error;
58562+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58563+ error = -ENOENT;
58564+ goto out;
58565+ }
58566 audit_inode(name, nd->path.dentry, 0);
58567 if (open_flag & O_CREAT) {
58568 error = -EISDIR;
58569 goto out;
58570 }
58571+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58572+ error = -EACCES;
58573+ goto out;
58574+ }
58575 goto finish_open;
58576 case LAST_BIND:
58577 error = complete_walk(nd);
58578 if (error)
58579 return error;
58580+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
58581+ error = -ENOENT;
58582+ goto out;
58583+ }
58584+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58585+ error = -EACCES;
58586+ goto out;
58587+ }
58588 audit_inode(name, dir, 0);
58589 goto finish_open;
58590 }
58591@@ -2759,7 +2827,7 @@ retry_lookup:
58592 */
58593 }
58594 mutex_lock(&dir->d_inode->i_mutex);
58595- error = lookup_open(nd, path, file, op, got_write, opened);
58596+ error = lookup_open(nd, path, link, file, op, got_write, opened);
58597 mutex_unlock(&dir->d_inode->i_mutex);
58598
58599 if (error <= 0) {
58600@@ -2783,11 +2851,28 @@ retry_lookup:
58601 goto finish_open_created;
58602 }
58603
58604+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
58605+ error = -ENOENT;
58606+ goto exit_dput;
58607+ }
58608+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
58609+ error = -EACCES;
58610+ goto exit_dput;
58611+ }
58612+
58613 /*
58614 * create/update audit record if it already exists.
58615 */
58616- if (path->dentry->d_inode)
58617+ if (path->dentry->d_inode) {
58618+ /* only check if O_CREAT is specified, all other checks need to go
58619+ into may_open */
58620+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
58621+ error = -EACCES;
58622+ goto exit_dput;
58623+ }
58624+
58625 audit_inode(name, path->dentry, 0);
58626+ }
58627
58628 /*
58629 * If atomic_open() acquired write access it is dropped now due to
58630@@ -2828,6 +2913,11 @@ finish_lookup:
58631 }
58632 }
58633 BUG_ON(inode != path->dentry->d_inode);
58634+ /* if we're resolving a symlink to another symlink */
58635+ if (link && gr_handle_symlink_owner(link, inode)) {
58636+ error = -EACCES;
58637+ goto out;
58638+ }
58639 return 1;
58640 }
58641
58642@@ -2837,7 +2927,6 @@ finish_lookup:
58643 save_parent.dentry = nd->path.dentry;
58644 save_parent.mnt = mntget(path->mnt);
58645 nd->path.dentry = path->dentry;
58646-
58647 }
58648 nd->inode = inode;
58649 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
58650@@ -2846,6 +2935,16 @@ finish_lookup:
58651 path_put(&save_parent);
58652 return error;
58653 }
58654+
58655+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58656+ error = -ENOENT;
58657+ goto out;
58658+ }
58659+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58660+ error = -EACCES;
58661+ goto out;
58662+ }
58663+
58664 error = -EISDIR;
58665 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
58666 goto out;
58667@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58668 if (unlikely(error))
58669 goto out;
58670
58671- error = do_last(nd, &path, file, op, &opened, pathname);
58672+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
58673 while (unlikely(error > 0)) { /* trailing symlink */
58674 struct path link = path;
58675 void *cookie;
58676@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58677 error = follow_link(&link, nd, &cookie);
58678 if (unlikely(error))
58679 break;
58680- error = do_last(nd, &path, file, op, &opened, pathname);
58681+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
58682 put_link(nd, &link, cookie);
58683 }
58684 out:
58685@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
58686 goto unlock;
58687
58688 error = -EEXIST;
58689- if (dentry->d_inode)
58690+ if (dentry->d_inode) {
58691+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
58692+ error = -ENOENT;
58693+ }
58694 goto fail;
58695+ }
58696 /*
58697 * Special case - lookup gave negative, but... we had foo/bar/
58698 * From the vfs_mknod() POV we just have a negative dentry -
58699@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
58700 }
58701 EXPORT_SYMBOL(user_path_create);
58702
58703+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
58704+{
58705+ struct filename *tmp = getname(pathname);
58706+ struct dentry *res;
58707+ if (IS_ERR(tmp))
58708+ return ERR_CAST(tmp);
58709+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
58710+ if (IS_ERR(res))
58711+ putname(tmp);
58712+ else
58713+ *to = tmp;
58714+ return res;
58715+}
58716+
58717 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
58718 {
58719 int error = may_create(dir, dentry);
58720@@ -3177,6 +3294,17 @@ retry:
58721
58722 if (!IS_POSIXACL(path.dentry->d_inode))
58723 mode &= ~current_umask();
58724+
58725+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
58726+ error = -EPERM;
58727+ goto out;
58728+ }
58729+
58730+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
58731+ error = -EACCES;
58732+ goto out;
58733+ }
58734+
58735 error = security_path_mknod(&path, dentry, mode, dev);
58736 if (error)
58737 goto out;
58738@@ -3193,6 +3321,8 @@ retry:
58739 break;
58740 }
58741 out:
58742+ if (!error)
58743+ gr_handle_create(dentry, path.mnt);
58744 done_path_create(&path, dentry);
58745 if (retry_estale(error, lookup_flags)) {
58746 lookup_flags |= LOOKUP_REVAL;
58747@@ -3245,9 +3375,16 @@ retry:
58748
58749 if (!IS_POSIXACL(path.dentry->d_inode))
58750 mode &= ~current_umask();
58751+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
58752+ error = -EACCES;
58753+ goto out;
58754+ }
58755 error = security_path_mkdir(&path, dentry, mode);
58756 if (!error)
58757 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
58758+ if (!error)
58759+ gr_handle_create(dentry, path.mnt);
58760+out:
58761 done_path_create(&path, dentry);
58762 if (retry_estale(error, lookup_flags)) {
58763 lookup_flags |= LOOKUP_REVAL;
58764@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
58765 struct filename *name;
58766 struct dentry *dentry;
58767 struct nameidata nd;
58768+ ino_t saved_ino = 0;
58769+ dev_t saved_dev = 0;
58770 unsigned int lookup_flags = 0;
58771 retry:
58772 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58773@@ -3360,10 +3499,21 @@ retry:
58774 error = -ENOENT;
58775 goto exit3;
58776 }
58777+
58778+ saved_ino = dentry->d_inode->i_ino;
58779+ saved_dev = gr_get_dev_from_dentry(dentry);
58780+
58781+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
58782+ error = -EACCES;
58783+ goto exit3;
58784+ }
58785+
58786 error = security_path_rmdir(&nd.path, dentry);
58787 if (error)
58788 goto exit3;
58789 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
58790+ if (!error && (saved_dev || saved_ino))
58791+ gr_handle_delete(saved_ino, saved_dev);
58792 exit3:
58793 dput(dentry);
58794 exit2:
58795@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
58796 struct dentry *dentry;
58797 struct nameidata nd;
58798 struct inode *inode = NULL;
58799+ ino_t saved_ino = 0;
58800+ dev_t saved_dev = 0;
58801 unsigned int lookup_flags = 0;
58802 retry:
58803 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58804@@ -3455,10 +3607,22 @@ retry:
58805 if (!inode)
58806 goto slashes;
58807 ihold(inode);
58808+
58809+ if (inode->i_nlink <= 1) {
58810+ saved_ino = inode->i_ino;
58811+ saved_dev = gr_get_dev_from_dentry(dentry);
58812+ }
58813+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
58814+ error = -EACCES;
58815+ goto exit2;
58816+ }
58817+
58818 error = security_path_unlink(&nd.path, dentry);
58819 if (error)
58820 goto exit2;
58821 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
58822+ if (!error && (saved_ino || saved_dev))
58823+ gr_handle_delete(saved_ino, saved_dev);
58824 exit2:
58825 dput(dentry);
58826 }
58827@@ -3536,9 +3700,17 @@ retry:
58828 if (IS_ERR(dentry))
58829 goto out_putname;
58830
58831+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
58832+ error = -EACCES;
58833+ goto out;
58834+ }
58835+
58836 error = security_path_symlink(&path, dentry, from->name);
58837 if (!error)
58838 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
58839+ if (!error)
58840+ gr_handle_create(dentry, path.mnt);
58841+out:
58842 done_path_create(&path, dentry);
58843 if (retry_estale(error, lookup_flags)) {
58844 lookup_flags |= LOOKUP_REVAL;
58845@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
58846 {
58847 struct dentry *new_dentry;
58848 struct path old_path, new_path;
58849+ struct filename *to = NULL;
58850 int how = 0;
58851 int error;
58852
58853@@ -3635,7 +3808,7 @@ retry:
58854 if (error)
58855 return error;
58856
58857- new_dentry = user_path_create(newdfd, newname, &new_path,
58858+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
58859 (how & LOOKUP_REVAL));
58860 error = PTR_ERR(new_dentry);
58861 if (IS_ERR(new_dentry))
58862@@ -3647,11 +3820,28 @@ retry:
58863 error = may_linkat(&old_path);
58864 if (unlikely(error))
58865 goto out_dput;
58866+
58867+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
58868+ old_path.dentry->d_inode,
58869+ old_path.dentry->d_inode->i_mode, to)) {
58870+ error = -EACCES;
58871+ goto out_dput;
58872+ }
58873+
58874+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
58875+ old_path.dentry, old_path.mnt, to)) {
58876+ error = -EACCES;
58877+ goto out_dput;
58878+ }
58879+
58880 error = security_path_link(old_path.dentry, &new_path, new_dentry);
58881 if (error)
58882 goto out_dput;
58883 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
58884+ if (!error)
58885+ gr_handle_create(new_dentry, new_path.mnt);
58886 out_dput:
58887+ putname(to);
58888 done_path_create(&new_path, new_dentry);
58889 if (retry_estale(error, how)) {
58890 how |= LOOKUP_REVAL;
58891@@ -3897,12 +4087,21 @@ retry:
58892 if (new_dentry == trap)
58893 goto exit5;
58894
58895+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
58896+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
58897+ to);
58898+ if (error)
58899+ goto exit5;
58900+
58901 error = security_path_rename(&oldnd.path, old_dentry,
58902 &newnd.path, new_dentry);
58903 if (error)
58904 goto exit5;
58905 error = vfs_rename(old_dir->d_inode, old_dentry,
58906 new_dir->d_inode, new_dentry);
58907+ if (!error)
58908+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
58909+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
58910 exit5:
58911 dput(new_dentry);
58912 exit4:
58913@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
58914
58915 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
58916 {
58917+ char tmpbuf[64];
58918+ const char *newlink;
58919 int len;
58920
58921 len = PTR_ERR(link);
58922@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
58923 len = strlen(link);
58924 if (len > (unsigned) buflen)
58925 len = buflen;
58926- if (copy_to_user(buffer, link, len))
58927+
58928+ if (len < sizeof(tmpbuf)) {
58929+ memcpy(tmpbuf, link, len);
58930+ newlink = tmpbuf;
58931+ } else
58932+ newlink = link;
58933+
58934+ if (copy_to_user(buffer, newlink, len))
58935 len = -EFAULT;
58936 out:
58937 return len;
58938diff --git a/fs/namespace.c b/fs/namespace.c
58939index a45ba4f..44cfe66 100644
58940--- a/fs/namespace.c
58941+++ b/fs/namespace.c
58942@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
58943 if (!(sb->s_flags & MS_RDONLY))
58944 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
58945 up_write(&sb->s_umount);
58946+
58947+ gr_log_remount(mnt->mnt_devname, retval);
58948+
58949 return retval;
58950 }
58951
58952@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
58953 }
58954 br_write_unlock(&vfsmount_lock);
58955 namespace_unlock();
58956+
58957+ gr_log_unmount(mnt->mnt_devname, retval);
58958+
58959 return retval;
58960 }
58961
58962@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
58963 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58964 */
58965
58966-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58967+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58968 {
58969 struct path path;
58970 struct mount *mnt;
58971@@ -1342,7 +1348,7 @@ out:
58972 /*
58973 * The 2.0 compatible umount. No flags.
58974 */
58975-SYSCALL_DEFINE1(oldumount, char __user *, name)
58976+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58977 {
58978 return sys_umount(name, 0);
58979 }
58980@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58981 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58982 MS_STRICTATIME);
58983
58984+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58985+ retval = -EPERM;
58986+ goto dput_out;
58987+ }
58988+
58989+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58990+ retval = -EPERM;
58991+ goto dput_out;
58992+ }
58993+
58994 if (flags & MS_REMOUNT)
58995 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58996 data_page);
58997@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58998 dev_name, data_page);
58999 dput_out:
59000 path_put(&path);
59001+
59002+ gr_log_mount(dev_name, dir_name, retval);
59003+
59004 return retval;
59005 }
59006
59007@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
59008 * number incrementing at 10Ghz will take 12,427 years to wrap which
59009 * is effectively never, so we can ignore the possibility.
59010 */
59011-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
59012+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
59013
59014 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59015 {
59016@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
59017 kfree(new_ns);
59018 return ERR_PTR(ret);
59019 }
59020- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
59021+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
59022 atomic_set(&new_ns->count, 1);
59023 new_ns->root = NULL;
59024 INIT_LIST_HEAD(&new_ns->list);
59025@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
59026 }
59027 EXPORT_SYMBOL(mount_subtree);
59028
59029-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
59030- char __user *, type, unsigned long, flags, void __user *, data)
59031+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
59032+ const char __user *, type, unsigned long, flags, void __user *, data)
59033 {
59034 int ret;
59035 char *kernel_type;
59036@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
59037 if (error)
59038 goto out2;
59039
59040+ if (gr_handle_chroot_pivot()) {
59041+ error = -EPERM;
59042+ goto out2;
59043+ }
59044+
59045 get_fs_root(current->fs, &root);
59046 old_mp = lock_mount(&old);
59047 error = PTR_ERR(old_mp);
59048@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
59049 !nsown_capable(CAP_SYS_ADMIN))
59050 return -EPERM;
59051
59052- if (fs->users != 1)
59053+ if (atomic_read(&fs->users) != 1)
59054 return -EINVAL;
59055
59056 get_mnt_ns(mnt_ns);
59057diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
59058index cff089a..4c3d57a 100644
59059--- a/fs/nfs/callback.c
59060+++ b/fs/nfs/callback.c
59061@@ -211,7 +211,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
59062 struct svc_rqst *rqstp;
59063 int (*callback_svc)(void *vrqstp);
59064 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
59065- char svc_name[12];
59066 int ret;
59067
59068 nfs_callback_bc_serv(minorversion, xprt, serv);
59069@@ -235,10 +234,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
59070
59071 svc_sock_update_bufs(serv);
59072
59073- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
59074 cb_info->serv = serv;
59075 cb_info->rqst = rqstp;
59076- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
59077+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
59078 if (IS_ERR(cb_info->task)) {
59079 ret = PTR_ERR(cb_info->task);
59080 svc_exit_thread(cb_info->rqst);
59081diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
59082index a35582c..ebbdcd5 100644
59083--- a/fs/nfs/callback_xdr.c
59084+++ b/fs/nfs/callback_xdr.c
59085@@ -51,7 +51,7 @@ struct callback_op {
59086 callback_decode_arg_t decode_args;
59087 callback_encode_res_t encode_res;
59088 long res_maxsize;
59089-};
59090+} __do_const;
59091
59092 static struct callback_op callback_ops[];
59093
59094diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
59095index c1c7a9d..7afa0b8 100644
59096--- a/fs/nfs/inode.c
59097+++ b/fs/nfs/inode.c
59098@@ -1043,16 +1043,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
59099 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
59100 }
59101
59102-static atomic_long_t nfs_attr_generation_counter;
59103+static atomic_long_unchecked_t nfs_attr_generation_counter;
59104
59105 static unsigned long nfs_read_attr_generation_counter(void)
59106 {
59107- return atomic_long_read(&nfs_attr_generation_counter);
59108+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
59109 }
59110
59111 unsigned long nfs_inc_attr_generation_counter(void)
59112 {
59113- return atomic_long_inc_return(&nfs_attr_generation_counter);
59114+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
59115 }
59116
59117 void nfs_fattr_init(struct nfs_fattr *fattr)
59118diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
59119index 2c37442..9b9538b 100644
59120--- a/fs/nfs/nfs4state.c
59121+++ b/fs/nfs/nfs4state.c
59122@@ -1193,7 +1193,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
59123 snprintf(buf, sizeof(buf), "%s-manager",
59124 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
59125 rcu_read_unlock();
59126- task = kthread_run(nfs4_run_state_manager, clp, buf);
59127+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
59128 if (IS_ERR(task)) {
59129 printk(KERN_ERR "%s: kthread_run: %ld\n",
59130 __func__, PTR_ERR(task));
59131diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
59132index 27d74a2..c4c2a73 100644
59133--- a/fs/nfsd/nfs4proc.c
59134+++ b/fs/nfsd/nfs4proc.c
59135@@ -1126,7 +1126,7 @@ struct nfsd4_operation {
59136 nfsd4op_rsize op_rsize_bop;
59137 stateid_getter op_get_currentstateid;
59138 stateid_setter op_set_currentstateid;
59139-};
59140+} __do_const;
59141
59142 static struct nfsd4_operation nfsd4_ops[];
59143
59144diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
59145index 582321a..0224663 100644
59146--- a/fs/nfsd/nfs4xdr.c
59147+++ b/fs/nfsd/nfs4xdr.c
59148@@ -1458,7 +1458,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
59149
59150 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
59151
59152-static nfsd4_dec nfsd4_dec_ops[] = {
59153+static const nfsd4_dec nfsd4_dec_ops[] = {
59154 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59155 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59156 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59157@@ -1498,7 +1498,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
59158 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
59159 };
59160
59161-static nfsd4_dec nfsd41_dec_ops[] = {
59162+static const nfsd4_dec nfsd41_dec_ops[] = {
59163 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
59164 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
59165 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
59166@@ -1560,7 +1560,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
59167 };
59168
59169 struct nfsd4_minorversion_ops {
59170- nfsd4_dec *decoders;
59171+ const nfsd4_dec *decoders;
59172 int nops;
59173 };
59174
59175diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
59176index e76244e..9fe8f2f1 100644
59177--- a/fs/nfsd/nfscache.c
59178+++ b/fs/nfsd/nfscache.c
59179@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
59180 {
59181 struct svc_cacherep *rp = rqstp->rq_cacherep;
59182 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
59183- int len;
59184+ long len;
59185 size_t bufsize = 0;
59186
59187 if (!rp)
59188 return;
59189
59190- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
59191- len >>= 2;
59192+ if (statp) {
59193+ len = (char*)statp - (char*)resv->iov_base;
59194+ len = resv->iov_len - len;
59195+ len >>= 2;
59196+ }
59197
59198 /* Don't cache excessive amounts of data and XDR failures */
59199 if (!statp || len > (256 >> 2)) {
59200diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
59201index baf149a..76b86ad 100644
59202--- a/fs/nfsd/vfs.c
59203+++ b/fs/nfsd/vfs.c
59204@@ -940,7 +940,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59205 } else {
59206 oldfs = get_fs();
59207 set_fs(KERNEL_DS);
59208- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
59209+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
59210 set_fs(oldfs);
59211 }
59212
59213@@ -1027,7 +1027,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
59214
59215 /* Write the data. */
59216 oldfs = get_fs(); set_fs(KERNEL_DS);
59217- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
59218+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
59219 set_fs(oldfs);
59220 if (host_err < 0)
59221 goto out_nfserr;
59222@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
59223 */
59224
59225 oldfs = get_fs(); set_fs(KERNEL_DS);
59226- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
59227+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
59228 set_fs(oldfs);
59229
59230 if (host_err < 0)
59231diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
59232index fea6bd5..8ee9d81 100644
59233--- a/fs/nls/nls_base.c
59234+++ b/fs/nls/nls_base.c
59235@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
59236
59237 int register_nls(struct nls_table * nls)
59238 {
59239- struct nls_table ** tmp = &tables;
59240+ struct nls_table *tmp = tables;
59241
59242 if (nls->next)
59243 return -EBUSY;
59244
59245 spin_lock(&nls_lock);
59246- while (*tmp) {
59247- if (nls == *tmp) {
59248+ while (tmp) {
59249+ if (nls == tmp) {
59250 spin_unlock(&nls_lock);
59251 return -EBUSY;
59252 }
59253- tmp = &(*tmp)->next;
59254+ tmp = tmp->next;
59255 }
59256- nls->next = tables;
59257+ pax_open_kernel();
59258+ *(struct nls_table **)&nls->next = tables;
59259+ pax_close_kernel();
59260 tables = nls;
59261 spin_unlock(&nls_lock);
59262 return 0;
59263@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
59264
59265 int unregister_nls(struct nls_table * nls)
59266 {
59267- struct nls_table ** tmp = &tables;
59268+ struct nls_table * const * tmp = &tables;
59269
59270 spin_lock(&nls_lock);
59271 while (*tmp) {
59272 if (nls == *tmp) {
59273- *tmp = nls->next;
59274+ pax_open_kernel();
59275+ *(struct nls_table **)tmp = nls->next;
59276+ pax_close_kernel();
59277 spin_unlock(&nls_lock);
59278 return 0;
59279 }
59280diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
59281index 7424929..35f6be5 100644
59282--- a/fs/nls/nls_euc-jp.c
59283+++ b/fs/nls/nls_euc-jp.c
59284@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
59285 p_nls = load_nls("cp932");
59286
59287 if (p_nls) {
59288- table.charset2upper = p_nls->charset2upper;
59289- table.charset2lower = p_nls->charset2lower;
59290+ pax_open_kernel();
59291+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59292+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59293+ pax_close_kernel();
59294 return register_nls(&table);
59295 }
59296
59297diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
59298index e7bc1d7..06bd4bb 100644
59299--- a/fs/nls/nls_koi8-ru.c
59300+++ b/fs/nls/nls_koi8-ru.c
59301@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
59302 p_nls = load_nls("koi8-u");
59303
59304 if (p_nls) {
59305- table.charset2upper = p_nls->charset2upper;
59306- table.charset2lower = p_nls->charset2lower;
59307+ pax_open_kernel();
59308+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
59309+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
59310+ pax_close_kernel();
59311 return register_nls(&table);
59312 }
59313
59314diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
59315index 77cc85d..a1e6299 100644
59316--- a/fs/notify/fanotify/fanotify_user.c
59317+++ b/fs/notify/fanotify/fanotify_user.c
59318@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
59319
59320 fd = fanotify_event_metadata.fd;
59321 ret = -EFAULT;
59322- if (copy_to_user(buf, &fanotify_event_metadata,
59323- fanotify_event_metadata.event_len))
59324+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
59325+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
59326 goto out_close_fd;
59327
59328 ret = prepare_for_access_response(group, event, fd);
59329diff --git a/fs/notify/notification.c b/fs/notify/notification.c
59330index 7b51b05..5ea5ef6 100644
59331--- a/fs/notify/notification.c
59332+++ b/fs/notify/notification.c
59333@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
59334 * get set to 0 so it will never get 'freed'
59335 */
59336 static struct fsnotify_event *q_overflow_event;
59337-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59338+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59339
59340 /**
59341 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
59342@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
59343 */
59344 u32 fsnotify_get_cookie(void)
59345 {
59346- return atomic_inc_return(&fsnotify_sync_cookie);
59347+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
59348 }
59349 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
59350
59351diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
59352index aa411c3..c260a84 100644
59353--- a/fs/ntfs/dir.c
59354+++ b/fs/ntfs/dir.c
59355@@ -1329,7 +1329,7 @@ find_next_index_buffer:
59356 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
59357 ~(s64)(ndir->itype.index.block_size - 1)));
59358 /* Bounds checks. */
59359- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59360+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
59361 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
59362 "inode 0x%lx or driver bug.", vdir->i_ino);
59363 goto err_out;
59364diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
59365index c5670b8..2b43d9b 100644
59366--- a/fs/ntfs/file.c
59367+++ b/fs/ntfs/file.c
59368@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
59369 char *addr;
59370 size_t total = 0;
59371 unsigned len;
59372- int left;
59373+ unsigned left;
59374
59375 do {
59376 len = PAGE_CACHE_SIZE - ofs;
59377@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
59378 #endif /* NTFS_RW */
59379 };
59380
59381-const struct file_operations ntfs_empty_file_ops = {};
59382+const struct file_operations ntfs_empty_file_ops __read_only;
59383
59384-const struct inode_operations ntfs_empty_inode_ops = {};
59385+const struct inode_operations ntfs_empty_inode_ops __read_only;
59386diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
59387index 82650d5..db37dcf 100644
59388--- a/fs/ntfs/super.c
59389+++ b/fs/ntfs/super.c
59390@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59391 if (!silent)
59392 ntfs_error(sb, "Primary boot sector is invalid.");
59393 } else if (!silent)
59394- ntfs_error(sb, read_err_str, "primary");
59395+ ntfs_error(sb, read_err_str, "%s", "primary");
59396 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
59397 if (bh_primary)
59398 brelse(bh_primary);
59399@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59400 goto hotfix_primary_boot_sector;
59401 brelse(bh_backup);
59402 } else if (!silent)
59403- ntfs_error(sb, read_err_str, "backup");
59404+ ntfs_error(sb, read_err_str, "%s", "backup");
59405 /* Try to read NT3.51- backup boot sector. */
59406 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
59407 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
59408@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
59409 "sector.");
59410 brelse(bh_backup);
59411 } else if (!silent)
59412- ntfs_error(sb, read_err_str, "backup");
59413+ ntfs_error(sb, read_err_str, "%s", "backup");
59414 /* We failed. Cleanup and return. */
59415 if (bh_primary)
59416 brelse(bh_primary);
59417diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
59418index 20dfec7..e238cb7 100644
59419--- a/fs/ocfs2/aops.c
59420+++ b/fs/ocfs2/aops.c
59421@@ -1756,7 +1756,7 @@ try_again:
59422 goto out;
59423 } else if (ret == 1) {
59424 clusters_need = wc->w_clen;
59425- ret = ocfs2_refcount_cow(inode, filp, di_bh,
59426+ ret = ocfs2_refcount_cow(inode, di_bh,
59427 wc->w_cpos, wc->w_clen, UINT_MAX);
59428 if (ret) {
59429 mlog_errno(ret);
59430diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
59431index ff54014..ff125fd 100644
59432--- a/fs/ocfs2/file.c
59433+++ b/fs/ocfs2/file.c
59434@@ -370,7 +370,7 @@ static int ocfs2_cow_file_pos(struct inode *inode,
59435 if (!(ext_flags & OCFS2_EXT_REFCOUNTED))
59436 goto out;
59437
59438- return ocfs2_refcount_cow(inode, NULL, fe_bh, cpos, 1, cpos+1);
59439+ return ocfs2_refcount_cow(inode, fe_bh, cpos, 1, cpos+1);
59440
59441 out:
59442 return status;
59443@@ -899,7 +899,7 @@ static int ocfs2_zero_extend_get_range(struct inode *inode,
59444 zero_clusters = last_cpos - zero_cpos;
59445
59446 if (needs_cow) {
59447- rc = ocfs2_refcount_cow(inode, NULL, di_bh, zero_cpos,
59448+ rc = ocfs2_refcount_cow(inode, di_bh, zero_cpos,
59449 zero_clusters, UINT_MAX);
59450 if (rc) {
59451 mlog_errno(rc);
59452@@ -2078,7 +2078,7 @@ static int ocfs2_prepare_inode_for_refcount(struct inode *inode,
59453
59454 *meta_level = 1;
59455
59456- ret = ocfs2_refcount_cow(inode, file, di_bh, cpos, clusters, UINT_MAX);
59457+ ret = ocfs2_refcount_cow(inode, di_bh, cpos, clusters, UINT_MAX);
59458 if (ret)
59459 mlog_errno(ret);
59460 out:
59461diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
59462index aebeacd..0dcdd26 100644
59463--- a/fs/ocfs2/localalloc.c
59464+++ b/fs/ocfs2/localalloc.c
59465@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
59466 goto bail;
59467 }
59468
59469- atomic_inc(&osb->alloc_stats.moves);
59470+ atomic_inc_unchecked(&osb->alloc_stats.moves);
59471
59472 bail:
59473 if (handle)
59474diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
59475index f1fc172..452068b 100644
59476--- a/fs/ocfs2/move_extents.c
59477+++ b/fs/ocfs2/move_extents.c
59478@@ -69,7 +69,7 @@ static int __ocfs2_move_extent(handle_t *handle,
59479 u64 ino = ocfs2_metadata_cache_owner(context->et.et_ci);
59480 u64 old_blkno = ocfs2_clusters_to_blocks(inode->i_sb, p_cpos);
59481
59482- ret = ocfs2_duplicate_clusters_by_page(handle, context->file, cpos,
59483+ ret = ocfs2_duplicate_clusters_by_page(handle, inode, cpos,
59484 p_cpos, new_p_cpos, len);
59485 if (ret) {
59486 mlog_errno(ret);
59487diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
59488index d355e6e..578d905 100644
59489--- a/fs/ocfs2/ocfs2.h
59490+++ b/fs/ocfs2/ocfs2.h
59491@@ -235,11 +235,11 @@ enum ocfs2_vol_state
59492
59493 struct ocfs2_alloc_stats
59494 {
59495- atomic_t moves;
59496- atomic_t local_data;
59497- atomic_t bitmap_data;
59498- atomic_t bg_allocs;
59499- atomic_t bg_extends;
59500+ atomic_unchecked_t moves;
59501+ atomic_unchecked_t local_data;
59502+ atomic_unchecked_t bitmap_data;
59503+ atomic_unchecked_t bg_allocs;
59504+ atomic_unchecked_t bg_extends;
59505 };
59506
59507 enum ocfs2_local_alloc_state
59508diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
59509index 998b17e..aefe414 100644
59510--- a/fs/ocfs2/refcounttree.c
59511+++ b/fs/ocfs2/refcounttree.c
59512@@ -49,7 +49,6 @@
59513
59514 struct ocfs2_cow_context {
59515 struct inode *inode;
59516- struct file *file;
59517 u32 cow_start;
59518 u32 cow_len;
59519 struct ocfs2_extent_tree data_et;
59520@@ -66,7 +65,7 @@ struct ocfs2_cow_context {
59521 u32 *num_clusters,
59522 unsigned int *extent_flags);
59523 int (*cow_duplicate_clusters)(handle_t *handle,
59524- struct file *file,
59525+ struct inode *inode,
59526 u32 cpos, u32 old_cluster,
59527 u32 new_cluster, u32 new_len);
59528 };
59529@@ -2922,14 +2921,12 @@ static int ocfs2_clear_cow_buffer(handle_t *handle, struct buffer_head *bh)
59530 }
59531
59532 int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59533- struct file *file,
59534+ struct inode *inode,
59535 u32 cpos, u32 old_cluster,
59536 u32 new_cluster, u32 new_len)
59537 {
59538 int ret = 0, partial;
59539- struct inode *inode = file_inode(file);
59540- struct ocfs2_caching_info *ci = INODE_CACHE(inode);
59541- struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
59542+ struct super_block *sb = inode->i_sb;
59543 u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
59544 struct page *page;
59545 pgoff_t page_index;
59546@@ -2973,13 +2970,6 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59547 if (PAGE_CACHE_SIZE <= OCFS2_SB(sb)->s_clustersize)
59548 BUG_ON(PageDirty(page));
59549
59550- if (PageReadahead(page)) {
59551- page_cache_async_readahead(mapping,
59552- &file->f_ra, file,
59553- page, page_index,
59554- readahead_pages);
59555- }
59556-
59557 if (!PageUptodate(page)) {
59558 ret = block_read_full_page(page, ocfs2_get_block);
59559 if (ret) {
59560@@ -2999,7 +2989,8 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59561 }
59562 }
59563
59564- ocfs2_map_and_dirty_page(inode, handle, from, to,
59565+ ocfs2_map_and_dirty_page(inode,
59566+ handle, from, to,
59567 page, 0, &new_block);
59568 mark_page_accessed(page);
59569 unlock:
59570@@ -3015,12 +3006,11 @@ unlock:
59571 }
59572
59573 int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
59574- struct file *file,
59575+ struct inode *inode,
59576 u32 cpos, u32 old_cluster,
59577 u32 new_cluster, u32 new_len)
59578 {
59579 int ret = 0;
59580- struct inode *inode = file_inode(file);
59581 struct super_block *sb = inode->i_sb;
59582 struct ocfs2_caching_info *ci = INODE_CACHE(inode);
59583 int i, blocks = ocfs2_clusters_to_blocks(sb, new_len);
59584@@ -3145,7 +3135,7 @@ static int ocfs2_replace_clusters(handle_t *handle,
59585
59586 /*If the old clusters is unwritten, no need to duplicate. */
59587 if (!(ext_flags & OCFS2_EXT_UNWRITTEN)) {
59588- ret = context->cow_duplicate_clusters(handle, context->file,
59589+ ret = context->cow_duplicate_clusters(handle, context->inode,
59590 cpos, old, new, len);
59591 if (ret) {
59592 mlog_errno(ret);
59593@@ -3423,35 +3413,12 @@ static int ocfs2_replace_cow(struct ocfs2_cow_context *context)
59594 return ret;
59595 }
59596
59597-static void ocfs2_readahead_for_cow(struct inode *inode,
59598- struct file *file,
59599- u32 start, u32 len)
59600-{
59601- struct address_space *mapping;
59602- pgoff_t index;
59603- unsigned long num_pages;
59604- int cs_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits;
59605-
59606- if (!file)
59607- return;
59608-
59609- mapping = file->f_mapping;
59610- num_pages = (len << cs_bits) >> PAGE_CACHE_SHIFT;
59611- if (!num_pages)
59612- num_pages = 1;
59613-
59614- index = ((loff_t)start << cs_bits) >> PAGE_CACHE_SHIFT;
59615- page_cache_sync_readahead(mapping, &file->f_ra, file,
59616- index, num_pages);
59617-}
59618-
59619 /*
59620 * Starting at cpos, try to CoW write_len clusters. Don't CoW
59621 * past max_cpos. This will stop when it runs into a hole or an
59622 * unrefcounted extent.
59623 */
59624 static int ocfs2_refcount_cow_hunk(struct inode *inode,
59625- struct file *file,
59626 struct buffer_head *di_bh,
59627 u32 cpos, u32 write_len, u32 max_cpos)
59628 {
59629@@ -3480,8 +3447,6 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode,
59630
59631 BUG_ON(cow_len == 0);
59632
59633- ocfs2_readahead_for_cow(inode, file, cow_start, cow_len);
59634-
59635 context = kzalloc(sizeof(struct ocfs2_cow_context), GFP_NOFS);
59636 if (!context) {
59637 ret = -ENOMEM;
59638@@ -3503,7 +3468,6 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode,
59639 context->ref_root_bh = ref_root_bh;
59640 context->cow_duplicate_clusters = ocfs2_duplicate_clusters_by_page;
59641 context->get_clusters = ocfs2_di_get_clusters;
59642- context->file = file;
59643
59644 ocfs2_init_dinode_extent_tree(&context->data_et,
59645 INODE_CACHE(inode), di_bh);
59646@@ -3532,7 +3496,6 @@ out:
59647 * clusters between cpos and cpos+write_len are safe to modify.
59648 */
59649 int ocfs2_refcount_cow(struct inode *inode,
59650- struct file *file,
59651 struct buffer_head *di_bh,
59652 u32 cpos, u32 write_len, u32 max_cpos)
59653 {
59654@@ -3552,7 +3515,7 @@ int ocfs2_refcount_cow(struct inode *inode,
59655 num_clusters = write_len;
59656
59657 if (ext_flags & OCFS2_EXT_REFCOUNTED) {
59658- ret = ocfs2_refcount_cow_hunk(inode, file, di_bh, cpos,
59659+ ret = ocfs2_refcount_cow_hunk(inode, di_bh, cpos,
59660 num_clusters, max_cpos);
59661 if (ret) {
59662 mlog_errno(ret);
59663diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h
59664index 7754608..6422bbcdb 100644
59665--- a/fs/ocfs2/refcounttree.h
59666+++ b/fs/ocfs2/refcounttree.h
59667@@ -53,7 +53,7 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
59668 int *credits,
59669 int *ref_blocks);
59670 int ocfs2_refcount_cow(struct inode *inode,
59671- struct file *filep, struct buffer_head *di_bh,
59672+ struct buffer_head *di_bh,
59673 u32 cpos, u32 write_len, u32 max_cpos);
59674
59675 typedef int (ocfs2_post_refcount_func)(struct inode *inode,
59676@@ -85,11 +85,11 @@ int ocfs2_refcount_cow_xattr(struct inode *inode,
59677 u32 cpos, u32 write_len,
59678 struct ocfs2_post_refcount *post);
59679 int ocfs2_duplicate_clusters_by_page(handle_t *handle,
59680- struct file *file,
59681+ struct inode *inode,
59682 u32 cpos, u32 old_cluster,
59683 u32 new_cluster, u32 new_len);
59684 int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
59685- struct file *file,
59686+ struct inode *inode,
59687 u32 cpos, u32 old_cluster,
59688 u32 new_cluster, u32 new_len);
59689 int ocfs2_cow_sync_writeback(struct super_block *sb,
59690diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
59691index b7e74b5..19c6536 100644
59692--- a/fs/ocfs2/suballoc.c
59693+++ b/fs/ocfs2/suballoc.c
59694@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
59695 mlog_errno(status);
59696 goto bail;
59697 }
59698- atomic_inc(&osb->alloc_stats.bg_extends);
59699+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
59700
59701 /* You should never ask for this much metadata */
59702 BUG_ON(bits_wanted >
59703@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
59704 mlog_errno(status);
59705 goto bail;
59706 }
59707- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59708+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59709
59710 *suballoc_loc = res.sr_bg_blkno;
59711 *suballoc_bit_start = res.sr_bit_offset;
59712@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
59713 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
59714 res->sr_bits);
59715
59716- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59717+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59718
59719 BUG_ON(res->sr_bits != 1);
59720
59721@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
59722 mlog_errno(status);
59723 goto bail;
59724 }
59725- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59726+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59727
59728 BUG_ON(res.sr_bits != 1);
59729
59730@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59731 cluster_start,
59732 num_clusters);
59733 if (!status)
59734- atomic_inc(&osb->alloc_stats.local_data);
59735+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
59736 } else {
59737 if (min_clusters > (osb->bitmap_cpg - 1)) {
59738 /* The only paths asking for contiguousness
59739@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59740 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
59741 res.sr_bg_blkno,
59742 res.sr_bit_offset);
59743- atomic_inc(&osb->alloc_stats.bitmap_data);
59744+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
59745 *num_clusters = res.sr_bits;
59746 }
59747 }
59748diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
59749index 01b8516..579c4df 100644
59750--- a/fs/ocfs2/super.c
59751+++ b/fs/ocfs2/super.c
59752@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
59753 "%10s => GlobalAllocs: %d LocalAllocs: %d "
59754 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
59755 "Stats",
59756- atomic_read(&osb->alloc_stats.bitmap_data),
59757- atomic_read(&osb->alloc_stats.local_data),
59758- atomic_read(&osb->alloc_stats.bg_allocs),
59759- atomic_read(&osb->alloc_stats.moves),
59760- atomic_read(&osb->alloc_stats.bg_extends));
59761+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
59762+ atomic_read_unchecked(&osb->alloc_stats.local_data),
59763+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
59764+ atomic_read_unchecked(&osb->alloc_stats.moves),
59765+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
59766
59767 out += snprintf(buf + out, len - out,
59768 "%10s => State: %u Descriptor: %llu Size: %u bits "
59769@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
59770 spin_lock_init(&osb->osb_xattr_lock);
59771 ocfs2_init_steal_slots(osb);
59772
59773- atomic_set(&osb->alloc_stats.moves, 0);
59774- atomic_set(&osb->alloc_stats.local_data, 0);
59775- atomic_set(&osb->alloc_stats.bitmap_data, 0);
59776- atomic_set(&osb->alloc_stats.bg_allocs, 0);
59777- atomic_set(&osb->alloc_stats.bg_extends, 0);
59778+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
59779+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
59780+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
59781+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
59782+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
59783
59784 /* Copy the blockcheck stats from the superblock probe */
59785 osb->osb_ecc_stats = *stats;
59786diff --git a/fs/open.c b/fs/open.c
59787index 8c74100..4239c48 100644
59788--- a/fs/open.c
59789+++ b/fs/open.c
59790@@ -32,6 +32,8 @@
59791 #include <linux/dnotify.h>
59792 #include <linux/compat.h>
59793
59794+#define CREATE_TRACE_POINTS
59795+#include <trace/events/fs.h>
59796 #include "internal.h"
59797
59798 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
59799@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
59800 error = locks_verify_truncate(inode, NULL, length);
59801 if (!error)
59802 error = security_path_truncate(path);
59803+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
59804+ error = -EACCES;
59805 if (!error)
59806 error = do_truncate(path->dentry, length, 0, NULL);
59807
59808@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
59809 error = locks_verify_truncate(inode, f.file, length);
59810 if (!error)
59811 error = security_path_truncate(&f.file->f_path);
59812+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
59813+ error = -EACCES;
59814 if (!error)
59815 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
59816 sb_end_write(inode->i_sb);
59817@@ -360,6 +366,9 @@ retry:
59818 if (__mnt_is_readonly(path.mnt))
59819 res = -EROFS;
59820
59821+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
59822+ res = -EACCES;
59823+
59824 out_path_release:
59825 path_put(&path);
59826 if (retry_estale(res, lookup_flags)) {
59827@@ -391,6 +400,8 @@ retry:
59828 if (error)
59829 goto dput_and_out;
59830
59831+ gr_log_chdir(path.dentry, path.mnt);
59832+
59833 set_fs_pwd(current->fs, &path);
59834
59835 dput_and_out:
59836@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
59837 goto out_putf;
59838
59839 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
59840+
59841+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
59842+ error = -EPERM;
59843+
59844+ if (!error)
59845+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
59846+
59847 if (!error)
59848 set_fs_pwd(current->fs, &f.file->f_path);
59849 out_putf:
59850@@ -449,7 +467,13 @@ retry:
59851 if (error)
59852 goto dput_and_out;
59853
59854+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
59855+ goto dput_and_out;
59856+
59857 set_fs_root(current->fs, &path);
59858+
59859+ gr_handle_chroot_chdir(&path);
59860+
59861 error = 0;
59862 dput_and_out:
59863 path_put(&path);
59864@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
59865 if (error)
59866 return error;
59867 mutex_lock(&inode->i_mutex);
59868+
59869+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
59870+ error = -EACCES;
59871+ goto out_unlock;
59872+ }
59873+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
59874+ error = -EACCES;
59875+ goto out_unlock;
59876+ }
59877+
59878 error = security_path_chmod(path, mode);
59879 if (error)
59880 goto out_unlock;
59881@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
59882 uid = make_kuid(current_user_ns(), user);
59883 gid = make_kgid(current_user_ns(), group);
59884
59885+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
59886+ return -EACCES;
59887+
59888 newattrs.ia_valid = ATTR_CTIME;
59889 if (user != (uid_t) -1) {
59890 if (!uid_valid(uid))
59891@@ -946,6 +983,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
59892 } else {
59893 fsnotify_open(f);
59894 fd_install(fd, f);
59895+ trace_do_sys_open(tmp->name, flags, mode);
59896 }
59897 }
59898 putname(tmp);
59899diff --git a/fs/pipe.c b/fs/pipe.c
59900index d2c45e1..009fe1c 100644
59901--- a/fs/pipe.c
59902+++ b/fs/pipe.c
59903@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
59904
59905 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
59906 {
59907- if (pipe->files)
59908+ if (atomic_read(&pipe->files))
59909 mutex_lock_nested(&pipe->mutex, subclass);
59910 }
59911
59912@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
59913
59914 void pipe_unlock(struct pipe_inode_info *pipe)
59915 {
59916- if (pipe->files)
59917+ if (atomic_read(&pipe->files))
59918 mutex_unlock(&pipe->mutex);
59919 }
59920 EXPORT_SYMBOL(pipe_unlock);
59921@@ -449,9 +449,9 @@ redo:
59922 }
59923 if (bufs) /* More to do? */
59924 continue;
59925- if (!pipe->writers)
59926+ if (!atomic_read(&pipe->writers))
59927 break;
59928- if (!pipe->waiting_writers) {
59929+ if (!atomic_read(&pipe->waiting_writers)) {
59930 /* syscall merging: Usually we must not sleep
59931 * if O_NONBLOCK is set, or if we got some data.
59932 * But if a writer sleeps in kernel space, then
59933@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
59934 ret = 0;
59935 __pipe_lock(pipe);
59936
59937- if (!pipe->readers) {
59938+ if (!atomic_read(&pipe->readers)) {
59939 send_sig(SIGPIPE, current, 0);
59940 ret = -EPIPE;
59941 goto out;
59942@@ -562,7 +562,7 @@ redo1:
59943 for (;;) {
59944 int bufs;
59945
59946- if (!pipe->readers) {
59947+ if (!atomic_read(&pipe->readers)) {
59948 send_sig(SIGPIPE, current, 0);
59949 if (!ret)
59950 ret = -EPIPE;
59951@@ -653,9 +653,9 @@ redo2:
59952 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
59953 do_wakeup = 0;
59954 }
59955- pipe->waiting_writers++;
59956+ atomic_inc(&pipe->waiting_writers);
59957 pipe_wait(pipe);
59958- pipe->waiting_writers--;
59959+ atomic_dec(&pipe->waiting_writers);
59960 }
59961 out:
59962 __pipe_unlock(pipe);
59963@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59964 mask = 0;
59965 if (filp->f_mode & FMODE_READ) {
59966 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
59967- if (!pipe->writers && filp->f_version != pipe->w_counter)
59968+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
59969 mask |= POLLHUP;
59970 }
59971
59972@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59973 * Most Unices do not set POLLERR for FIFOs but on Linux they
59974 * behave exactly like pipes for poll().
59975 */
59976- if (!pipe->readers)
59977+ if (!atomic_read(&pipe->readers))
59978 mask |= POLLERR;
59979 }
59980
59981@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
59982
59983 __pipe_lock(pipe);
59984 if (file->f_mode & FMODE_READ)
59985- pipe->readers--;
59986+ atomic_dec(&pipe->readers);
59987 if (file->f_mode & FMODE_WRITE)
59988- pipe->writers--;
59989+ atomic_dec(&pipe->writers);
59990
59991- if (pipe->readers || pipe->writers) {
59992+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
59993 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
59994 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
59995 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
59996 }
59997 spin_lock(&inode->i_lock);
59998- if (!--pipe->files) {
59999+ if (atomic_dec_and_test(&pipe->files)) {
60000 inode->i_pipe = NULL;
60001 kill = 1;
60002 }
60003@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
60004 kfree(pipe);
60005 }
60006
60007-static struct vfsmount *pipe_mnt __read_mostly;
60008+struct vfsmount *pipe_mnt __read_mostly;
60009
60010 /*
60011 * pipefs_dname() is called from d_path().
60012@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
60013 goto fail_iput;
60014
60015 inode->i_pipe = pipe;
60016- pipe->files = 2;
60017- pipe->readers = pipe->writers = 1;
60018+ atomic_set(&pipe->files, 2);
60019+ atomic_set(&pipe->readers, 1);
60020+ atomic_set(&pipe->writers, 1);
60021 inode->i_fop = &pipefifo_fops;
60022
60023 /*
60024@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
60025 spin_lock(&inode->i_lock);
60026 if (inode->i_pipe) {
60027 pipe = inode->i_pipe;
60028- pipe->files++;
60029+ atomic_inc(&pipe->files);
60030 spin_unlock(&inode->i_lock);
60031 } else {
60032 spin_unlock(&inode->i_lock);
60033 pipe = alloc_pipe_info();
60034 if (!pipe)
60035 return -ENOMEM;
60036- pipe->files = 1;
60037+ atomic_set(&pipe->files, 1);
60038 spin_lock(&inode->i_lock);
60039 if (unlikely(inode->i_pipe)) {
60040- inode->i_pipe->files++;
60041+ atomic_inc(&inode->i_pipe->files);
60042 spin_unlock(&inode->i_lock);
60043 free_pipe_info(pipe);
60044 pipe = inode->i_pipe;
60045@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
60046 * opened, even when there is no process writing the FIFO.
60047 */
60048 pipe->r_counter++;
60049- if (pipe->readers++ == 0)
60050+ if (atomic_inc_return(&pipe->readers) == 1)
60051 wake_up_partner(pipe);
60052
60053- if (!is_pipe && !pipe->writers) {
60054+ if (!is_pipe && !atomic_read(&pipe->writers)) {
60055 if ((filp->f_flags & O_NONBLOCK)) {
60056 /* suppress POLLHUP until we have
60057 * seen a writer */
60058@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
60059 * errno=ENXIO when there is no process reading the FIFO.
60060 */
60061 ret = -ENXIO;
60062- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
60063+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
60064 goto err;
60065
60066 pipe->w_counter++;
60067- if (!pipe->writers++)
60068+ if (atomic_inc_return(&pipe->writers) == 1)
60069 wake_up_partner(pipe);
60070
60071- if (!is_pipe && !pipe->readers) {
60072+ if (!is_pipe && !atomic_read(&pipe->readers)) {
60073 if (wait_for_partner(pipe, &pipe->r_counter))
60074 goto err_wr;
60075 }
60076@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
60077 * the process can at least talk to itself.
60078 */
60079
60080- pipe->readers++;
60081- pipe->writers++;
60082+ atomic_inc(&pipe->readers);
60083+ atomic_inc(&pipe->writers);
60084 pipe->r_counter++;
60085 pipe->w_counter++;
60086- if (pipe->readers == 1 || pipe->writers == 1)
60087+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
60088 wake_up_partner(pipe);
60089 break;
60090
60091@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
60092 return 0;
60093
60094 err_rd:
60095- if (!--pipe->readers)
60096+ if (atomic_dec_and_test(&pipe->readers))
60097 wake_up_interruptible(&pipe->wait);
60098 ret = -ERESTARTSYS;
60099 goto err;
60100
60101 err_wr:
60102- if (!--pipe->writers)
60103+ if (atomic_dec_and_test(&pipe->writers))
60104 wake_up_interruptible(&pipe->wait);
60105 ret = -ERESTARTSYS;
60106 goto err;
60107
60108 err:
60109 spin_lock(&inode->i_lock);
60110- if (!--pipe->files) {
60111+ if (atomic_dec_and_test(&pipe->files)) {
60112 inode->i_pipe = NULL;
60113 kill = 1;
60114 }
60115diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
60116index 15af622..0e9f4467 100644
60117--- a/fs/proc/Kconfig
60118+++ b/fs/proc/Kconfig
60119@@ -30,12 +30,12 @@ config PROC_FS
60120
60121 config PROC_KCORE
60122 bool "/proc/kcore support" if !ARM
60123- depends on PROC_FS && MMU
60124+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
60125
60126 config PROC_VMCORE
60127 bool "/proc/vmcore support"
60128- depends on PROC_FS && CRASH_DUMP
60129- default y
60130+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
60131+ default n
60132 help
60133 Exports the dump image of crashed kernel in ELF format.
60134
60135@@ -59,8 +59,8 @@ config PROC_SYSCTL
60136 limited in memory.
60137
60138 config PROC_PAGE_MONITOR
60139- default y
60140- depends on PROC_FS && MMU
60141+ default n
60142+ depends on PROC_FS && MMU && !GRKERNSEC
60143 bool "Enable /proc page monitoring" if EXPERT
60144 help
60145 Various /proc files exist to monitor process memory utilization:
60146diff --git a/fs/proc/array.c b/fs/proc/array.c
60147index cbd0f1b..adec3f0 100644
60148--- a/fs/proc/array.c
60149+++ b/fs/proc/array.c
60150@@ -60,6 +60,7 @@
60151 #include <linux/tty.h>
60152 #include <linux/string.h>
60153 #include <linux/mman.h>
60154+#include <linux/grsecurity.h>
60155 #include <linux/proc_fs.h>
60156 #include <linux/ioport.h>
60157 #include <linux/uaccess.h>
60158@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
60159 seq_putc(m, '\n');
60160 }
60161
60162+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60163+static inline void task_pax(struct seq_file *m, struct task_struct *p)
60164+{
60165+ if (p->mm)
60166+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
60167+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
60168+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
60169+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
60170+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
60171+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
60172+ else
60173+ seq_printf(m, "PaX:\t-----\n");
60174+}
60175+#endif
60176+
60177 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60178 struct pid *pid, struct task_struct *task)
60179 {
60180@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
60181 task_cpus_allowed(m, task);
60182 cpuset_task_status_allowed(m, task);
60183 task_context_switch_counts(m, task);
60184+
60185+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60186+ task_pax(m, task);
60187+#endif
60188+
60189+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
60190+ task_grsec_rbac(m, task);
60191+#endif
60192+
60193 return 0;
60194 }
60195
60196+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60197+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60198+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60199+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60200+#endif
60201+
60202 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60203 struct pid *pid, struct task_struct *task, int whole)
60204 {
60205@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60206 char tcomm[sizeof(task->comm)];
60207 unsigned long flags;
60208
60209+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60210+ if (current->exec_id != m->exec_id) {
60211+ gr_log_badprocpid("stat");
60212+ return 0;
60213+ }
60214+#endif
60215+
60216 state = *get_task_state(task);
60217 vsize = eip = esp = 0;
60218 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60219@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60220 gtime = task_gtime(task);
60221 }
60222
60223+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60224+ if (PAX_RAND_FLAGS(mm)) {
60225+ eip = 0;
60226+ esp = 0;
60227+ wchan = 0;
60228+ }
60229+#endif
60230+#ifdef CONFIG_GRKERNSEC_HIDESYM
60231+ wchan = 0;
60232+ eip =0;
60233+ esp =0;
60234+#endif
60235+
60236 /* scale priority and nice values from timeslices to -20..20 */
60237 /* to make it look like a "normal" Unix priority/nice value */
60238 priority = task_prio(task);
60239@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60240 seq_put_decimal_ull(m, ' ', vsize);
60241 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
60242 seq_put_decimal_ull(m, ' ', rsslim);
60243+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60244+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
60245+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
60246+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
60247+#else
60248 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
60249 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
60250 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
60251+#endif
60252 seq_put_decimal_ull(m, ' ', esp);
60253 seq_put_decimal_ull(m, ' ', eip);
60254 /* The signal information here is obsolete.
60255@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
60256 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
60257 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
60258
60259- if (mm && permitted) {
60260+ if (mm && permitted
60261+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60262+ && !PAX_RAND_FLAGS(mm)
60263+#endif
60264+ ) {
60265 seq_put_decimal_ull(m, ' ', mm->start_data);
60266 seq_put_decimal_ull(m, ' ', mm->end_data);
60267 seq_put_decimal_ull(m, ' ', mm->start_brk);
60268@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60269 struct pid *pid, struct task_struct *task)
60270 {
60271 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
60272- struct mm_struct *mm = get_task_mm(task);
60273+ struct mm_struct *mm;
60274
60275+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60276+ if (current->exec_id != m->exec_id) {
60277+ gr_log_badprocpid("statm");
60278+ return 0;
60279+ }
60280+#endif
60281+ mm = get_task_mm(task);
60282 if (mm) {
60283 size = task_statm(mm, &shared, &text, &data, &resident);
60284 mmput(mm);
60285@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
60286 return 0;
60287 }
60288
60289+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60290+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
60291+{
60292+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
60293+}
60294+#endif
60295+
60296 #ifdef CONFIG_CHECKPOINT_RESTORE
60297 static struct pid *
60298 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
60299diff --git a/fs/proc/base.c b/fs/proc/base.c
60300index c3834da..b402b2b 100644
60301--- a/fs/proc/base.c
60302+++ b/fs/proc/base.c
60303@@ -113,6 +113,14 @@ struct pid_entry {
60304 union proc_op op;
60305 };
60306
60307+struct getdents_callback {
60308+ struct linux_dirent __user * current_dir;
60309+ struct linux_dirent __user * previous;
60310+ struct file * file;
60311+ int count;
60312+ int error;
60313+};
60314+
60315 #define NOD(NAME, MODE, IOP, FOP, OP) { \
60316 .name = (NAME), \
60317 .len = sizeof(NAME) - 1, \
60318@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
60319 if (!mm->arg_end)
60320 goto out_mm; /* Shh! No looking before we're done */
60321
60322+ if (gr_acl_handle_procpidmem(task))
60323+ goto out_mm;
60324+
60325 len = mm->arg_end - mm->arg_start;
60326
60327 if (len > PAGE_SIZE)
60328@@ -237,12 +248,28 @@ out:
60329 return res;
60330 }
60331
60332+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60333+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60334+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60335+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60336+#endif
60337+
60338 static int proc_pid_auxv(struct task_struct *task, char *buffer)
60339 {
60340 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
60341 int res = PTR_ERR(mm);
60342 if (mm && !IS_ERR(mm)) {
60343 unsigned int nwords = 0;
60344+
60345+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60346+ /* allow if we're currently ptracing this task */
60347+ if (PAX_RAND_FLAGS(mm) &&
60348+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
60349+ mmput(mm);
60350+ return 0;
60351+ }
60352+#endif
60353+
60354 do {
60355 nwords += 2;
60356 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
60357@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
60358 }
60359
60360
60361-#ifdef CONFIG_KALLSYMS
60362+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60363 /*
60364 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
60365 * Returns the resolved symbol. If that fails, simply return the address.
60366@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
60367 mutex_unlock(&task->signal->cred_guard_mutex);
60368 }
60369
60370-#ifdef CONFIG_STACKTRACE
60371+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60372
60373 #define MAX_STACK_TRACE_DEPTH 64
60374
60375@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
60376 return count;
60377 }
60378
60379-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60380+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60381 static int proc_pid_syscall(struct task_struct *task, char *buffer)
60382 {
60383 long nr;
60384@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
60385 /************************************************************************/
60386
60387 /* permission checks */
60388-static int proc_fd_access_allowed(struct inode *inode)
60389+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
60390 {
60391 struct task_struct *task;
60392 int allowed = 0;
60393@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
60394 */
60395 task = get_proc_task(inode);
60396 if (task) {
60397- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60398+ if (log)
60399+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
60400+ else
60401+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
60402 put_task_struct(task);
60403 }
60404 return allowed;
60405@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
60406 struct task_struct *task,
60407 int hide_pid_min)
60408 {
60409+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60410+ return false;
60411+
60412+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60413+ rcu_read_lock();
60414+ {
60415+ const struct cred *tmpcred = current_cred();
60416+ const struct cred *cred = __task_cred(task);
60417+
60418+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
60419+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60420+ || in_group_p(grsec_proc_gid)
60421+#endif
60422+ ) {
60423+ rcu_read_unlock();
60424+ return true;
60425+ }
60426+ }
60427+ rcu_read_unlock();
60428+
60429+ if (!pid->hide_pid)
60430+ return false;
60431+#endif
60432+
60433 if (pid->hide_pid < hide_pid_min)
60434 return true;
60435 if (in_group_p(pid->pid_gid))
60436 return true;
60437+
60438 return ptrace_may_access(task, PTRACE_MODE_READ);
60439 }
60440
60441@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
60442 put_task_struct(task);
60443
60444 if (!has_perms) {
60445+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60446+ {
60447+#else
60448 if (pid->hide_pid == 2) {
60449+#endif
60450 /*
60451 * Let's make getdents(), stat(), and open()
60452 * consistent with each other. If a process
60453@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60454 if (!task)
60455 return -ESRCH;
60456
60457+ if (gr_acl_handle_procpidmem(task)) {
60458+ put_task_struct(task);
60459+ return -EPERM;
60460+ }
60461+
60462 mm = mm_access(task, mode);
60463 put_task_struct(task);
60464
60465@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
60466
60467 file->private_data = mm;
60468
60469+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60470+ file->f_version = current->exec_id;
60471+#endif
60472+
60473 return 0;
60474 }
60475
60476@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60477 ssize_t copied;
60478 char *page;
60479
60480+#ifdef CONFIG_GRKERNSEC
60481+ if (write)
60482+ return -EPERM;
60483+#endif
60484+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60485+ if (file->f_version != current->exec_id) {
60486+ gr_log_badprocpid("mem");
60487+ return 0;
60488+ }
60489+#endif
60490+
60491 if (!mm)
60492 return 0;
60493
60494@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
60495 goto free;
60496
60497 while (count > 0) {
60498- int this_len = min_t(int, count, PAGE_SIZE);
60499+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
60500
60501 if (write && copy_from_user(page, buf, this_len)) {
60502 copied = -EFAULT;
60503@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60504 if (!mm)
60505 return 0;
60506
60507+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60508+ if (file->f_version != current->exec_id) {
60509+ gr_log_badprocpid("environ");
60510+ return 0;
60511+ }
60512+#endif
60513+
60514 page = (char *)__get_free_page(GFP_TEMPORARY);
60515 if (!page)
60516 return -ENOMEM;
60517@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
60518 goto free;
60519 while (count > 0) {
60520 size_t this_len, max_len;
60521- int retval;
60522+ ssize_t retval;
60523
60524 if (src >= (mm->env_end - mm->env_start))
60525 break;
60526@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
60527 int error = -EACCES;
60528
60529 /* Are we allowed to snoop on the tasks file descriptors? */
60530- if (!proc_fd_access_allowed(inode))
60531+ if (!proc_fd_access_allowed(inode, 0))
60532 goto out;
60533
60534 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60535@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
60536 struct path path;
60537
60538 /* Are we allowed to snoop on the tasks file descriptors? */
60539- if (!proc_fd_access_allowed(inode))
60540- goto out;
60541+ /* logging this is needed for learning on chromium to work properly,
60542+ but we don't want to flood the logs from 'ps' which does a readlink
60543+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
60544+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
60545+ */
60546+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
60547+ if (!proc_fd_access_allowed(inode,0))
60548+ goto out;
60549+ } else {
60550+ if (!proc_fd_access_allowed(inode,1))
60551+ goto out;
60552+ }
60553
60554 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
60555 if (error)
60556@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
60557 rcu_read_lock();
60558 cred = __task_cred(task);
60559 inode->i_uid = cred->euid;
60560+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60561+ inode->i_gid = grsec_proc_gid;
60562+#else
60563 inode->i_gid = cred->egid;
60564+#endif
60565 rcu_read_unlock();
60566 }
60567 security_task_to_inode(task, inode);
60568@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
60569 return -ENOENT;
60570 }
60571 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60572+#ifdef CONFIG_GRKERNSEC_PROC_USER
60573+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60574+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60575+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60576+#endif
60577 task_dumpable(task)) {
60578 cred = __task_cred(task);
60579 stat->uid = cred->euid;
60580+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60581+ stat->gid = grsec_proc_gid;
60582+#else
60583 stat->gid = cred->egid;
60584+#endif
60585 }
60586 }
60587 rcu_read_unlock();
60588@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
60589
60590 if (task) {
60591 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
60592+#ifdef CONFIG_GRKERNSEC_PROC_USER
60593+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
60594+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60595+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
60596+#endif
60597 task_dumpable(task)) {
60598 rcu_read_lock();
60599 cred = __task_cred(task);
60600 inode->i_uid = cred->euid;
60601+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60602+ inode->i_gid = grsec_proc_gid;
60603+#else
60604 inode->i_gid = cred->egid;
60605+#endif
60606 rcu_read_unlock();
60607 } else {
60608 inode->i_uid = GLOBAL_ROOT_UID;
60609@@ -2196,6 +2314,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
60610 if (!task)
60611 goto out_no_task;
60612
60613+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60614+ goto out;
60615+
60616 /*
60617 * Yes, it does not scale. And it should not. Don't add
60618 * new entries into /proc/<tgid>/ without very good reasons.
60619@@ -2240,6 +2361,9 @@ static int proc_pident_readdir(struct file *filp,
60620 if (!task)
60621 goto out_no_task;
60622
60623+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60624+ goto out;
60625+
60626 ret = 0;
60627 i = filp->f_pos;
60628 switch (i) {
60629@@ -2653,7 +2777,7 @@ static const struct pid_entry tgid_base_stuff[] = {
60630 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
60631 #endif
60632 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60633-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60634+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60635 INF("syscall", S_IRUGO, proc_pid_syscall),
60636 #endif
60637 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60638@@ -2678,10 +2802,10 @@ static const struct pid_entry tgid_base_stuff[] = {
60639 #ifdef CONFIG_SECURITY
60640 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60641 #endif
60642-#ifdef CONFIG_KALLSYMS
60643+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60644 INF("wchan", S_IRUGO, proc_pid_wchan),
60645 #endif
60646-#ifdef CONFIG_STACKTRACE
60647+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60648 ONE("stack", S_IRUGO, proc_pid_stack),
60649 #endif
60650 #ifdef CONFIG_SCHEDSTATS
60651@@ -2715,6 +2839,9 @@ static const struct pid_entry tgid_base_stuff[] = {
60652 #ifdef CONFIG_HARDWALL
60653 INF("hardwall", S_IRUGO, proc_pid_hardwall),
60654 #endif
60655+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60656+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
60657+#endif
60658 #ifdef CONFIG_USER_NS
60659 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
60660 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
60661@@ -2847,7 +2974,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
60662 if (!inode)
60663 goto out;
60664
60665+#ifdef CONFIG_GRKERNSEC_PROC_USER
60666+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
60667+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60668+ inode->i_gid = grsec_proc_gid;
60669+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
60670+#else
60671 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
60672+#endif
60673 inode->i_op = &proc_tgid_base_inode_operations;
60674 inode->i_fop = &proc_tgid_base_operations;
60675 inode->i_flags|=S_IMMUTABLE;
60676@@ -2885,7 +3019,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
60677 if (!task)
60678 goto out;
60679
60680+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
60681+ goto out_put_task;
60682+
60683 result = proc_pid_instantiate(dir, dentry, task, NULL);
60684+out_put_task:
60685 put_task_struct(task);
60686 out:
60687 return result;
60688@@ -2948,6 +3086,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
60689 static int fake_filldir(void *buf, const char *name, int namelen,
60690 loff_t offset, u64 ino, unsigned d_type)
60691 {
60692+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
60693+ __buf->error = -EINVAL;
60694 return 0;
60695 }
60696
60697@@ -3007,7 +3147,7 @@ static const struct pid_entry tid_base_stuff[] = {
60698 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
60699 #endif
60700 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
60701-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
60702+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
60703 INF("syscall", S_IRUGO, proc_pid_syscall),
60704 #endif
60705 INF("cmdline", S_IRUGO, proc_pid_cmdline),
60706@@ -3034,10 +3174,10 @@ static const struct pid_entry tid_base_stuff[] = {
60707 #ifdef CONFIG_SECURITY
60708 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
60709 #endif
60710-#ifdef CONFIG_KALLSYMS
60711+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60712 INF("wchan", S_IRUGO, proc_pid_wchan),
60713 #endif
60714-#ifdef CONFIG_STACKTRACE
60715+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
60716 ONE("stack", S_IRUGO, proc_pid_stack),
60717 #endif
60718 #ifdef CONFIG_SCHEDSTATS
60719diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
60720index 82676e3..5f8518a 100644
60721--- a/fs/proc/cmdline.c
60722+++ b/fs/proc/cmdline.c
60723@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
60724
60725 static int __init proc_cmdline_init(void)
60726 {
60727+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60728+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
60729+#else
60730 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
60731+#endif
60732 return 0;
60733 }
60734 module_init(proc_cmdline_init);
60735diff --git a/fs/proc/devices.c b/fs/proc/devices.c
60736index b143471..bb105e5 100644
60737--- a/fs/proc/devices.c
60738+++ b/fs/proc/devices.c
60739@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
60740
60741 static int __init proc_devices_init(void)
60742 {
60743+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60744+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
60745+#else
60746 proc_create("devices", 0, NULL, &proc_devinfo_operations);
60747+#endif
60748 return 0;
60749 }
60750 module_init(proc_devices_init);
60751diff --git a/fs/proc/fd.c b/fs/proc/fd.c
60752index d7a4a28..0201742 100644
60753--- a/fs/proc/fd.c
60754+++ b/fs/proc/fd.c
60755@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
60756 if (!task)
60757 return -ENOENT;
60758
60759- files = get_files_struct(task);
60760+ if (!gr_acl_handle_procpidmem(task))
60761+ files = get_files_struct(task);
60762 put_task_struct(task);
60763
60764 if (files) {
60765@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
60766 */
60767 int proc_fd_permission(struct inode *inode, int mask)
60768 {
60769+ struct task_struct *task;
60770 int rv = generic_permission(inode, mask);
60771- if (rv == 0)
60772- return 0;
60773+
60774 if (task_pid(current) == proc_pid(inode))
60775 rv = 0;
60776+
60777+ task = get_proc_task(inode);
60778+ if (task == NULL)
60779+ return rv;
60780+
60781+ if (gr_acl_handle_procpidmem(task))
60782+ rv = -EACCES;
60783+
60784+ put_task_struct(task);
60785+
60786 return rv;
60787 }
60788
60789diff --git a/fs/proc/inode.c b/fs/proc/inode.c
60790index 073aea6..0630370 100644
60791--- a/fs/proc/inode.c
60792+++ b/fs/proc/inode.c
60793@@ -23,11 +23,17 @@
60794 #include <linux/slab.h>
60795 #include <linux/mount.h>
60796 #include <linux/magic.h>
60797+#include <linux/grsecurity.h>
60798
60799 #include <asm/uaccess.h>
60800
60801 #include "internal.h"
60802
60803+#ifdef CONFIG_PROC_SYSCTL
60804+extern const struct inode_operations proc_sys_inode_operations;
60805+extern const struct inode_operations proc_sys_dir_operations;
60806+#endif
60807+
60808 static void proc_evict_inode(struct inode *inode)
60809 {
60810 struct proc_dir_entry *de;
60811@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
60812 ns = PROC_I(inode)->ns.ns;
60813 if (ns_ops && ns)
60814 ns_ops->put(ns);
60815+
60816+#ifdef CONFIG_PROC_SYSCTL
60817+ if (inode->i_op == &proc_sys_inode_operations ||
60818+ inode->i_op == &proc_sys_dir_operations)
60819+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
60820+#endif
60821+
60822 }
60823
60824 static struct kmem_cache * proc_inode_cachep;
60825@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
60826 if (de->mode) {
60827 inode->i_mode = de->mode;
60828 inode->i_uid = de->uid;
60829+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60830+ inode->i_gid = grsec_proc_gid;
60831+#else
60832 inode->i_gid = de->gid;
60833+#endif
60834 }
60835 if (de->size)
60836 inode->i_size = de->size;
60837diff --git a/fs/proc/internal.h b/fs/proc/internal.h
60838index d600fb0..3b495fe 100644
60839--- a/fs/proc/internal.h
60840+++ b/fs/proc/internal.h
60841@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
60842 struct pid *, struct task_struct *);
60843 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
60844 struct pid *, struct task_struct *);
60845+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60846+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
60847+#endif
60848
60849 /*
60850 * base.c
60851diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
60852index 0a22194..a9fc8c1 100644
60853--- a/fs/proc/kcore.c
60854+++ b/fs/proc/kcore.c
60855@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60856 * the addresses in the elf_phdr on our list.
60857 */
60858 start = kc_offset_to_vaddr(*fpos - elf_buflen);
60859- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
60860+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
60861+ if (tsz > buflen)
60862 tsz = buflen;
60863-
60864+
60865 while (buflen) {
60866 struct kcore_list *m;
60867
60868@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60869 kfree(elf_buf);
60870 } else {
60871 if (kern_addr_valid(start)) {
60872- unsigned long n;
60873+ char *elf_buf;
60874+ mm_segment_t oldfs;
60875
60876- n = copy_to_user(buffer, (char *)start, tsz);
60877- /*
60878- * We cannot distinguish between fault on source
60879- * and fault on destination. When this happens
60880- * we clear too and hope it will trigger the
60881- * EFAULT again.
60882- */
60883- if (n) {
60884- if (clear_user(buffer + tsz - n,
60885- n))
60886+ elf_buf = kmalloc(tsz, GFP_KERNEL);
60887+ if (!elf_buf)
60888+ return -ENOMEM;
60889+ oldfs = get_fs();
60890+ set_fs(KERNEL_DS);
60891+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
60892+ set_fs(oldfs);
60893+ if (copy_to_user(buffer, elf_buf, tsz)) {
60894+ kfree(elf_buf);
60895 return -EFAULT;
60896+ }
60897 }
60898+ set_fs(oldfs);
60899+ kfree(elf_buf);
60900 } else {
60901 if (clear_user(buffer, tsz))
60902 return -EFAULT;
60903@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60904
60905 static int open_kcore(struct inode *inode, struct file *filp)
60906 {
60907+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
60908+ return -EPERM;
60909+#endif
60910 if (!capable(CAP_SYS_RAWIO))
60911 return -EPERM;
60912 if (kcore_need_update)
60913diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
60914index 5aa847a..f77c8d4 100644
60915--- a/fs/proc/meminfo.c
60916+++ b/fs/proc/meminfo.c
60917@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
60918 vmi.used >> 10,
60919 vmi.largest_chunk >> 10
60920 #ifdef CONFIG_MEMORY_FAILURE
60921- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60922+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60923 #endif
60924 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
60925 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
60926diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
60927index ccfd99b..1b7e255 100644
60928--- a/fs/proc/nommu.c
60929+++ b/fs/proc/nommu.c
60930@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
60931 if (len < 1)
60932 len = 1;
60933 seq_printf(m, "%*c", len, ' ');
60934- seq_path(m, &file->f_path, "");
60935+ seq_path(m, &file->f_path, "\n\\");
60936 }
60937
60938 seq_putc(m, '\n');
60939diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
60940index 986e832..6e8e859 100644
60941--- a/fs/proc/proc_net.c
60942+++ b/fs/proc/proc_net.c
60943@@ -23,6 +23,7 @@
60944 #include <linux/nsproxy.h>
60945 #include <net/net_namespace.h>
60946 #include <linux/seq_file.h>
60947+#include <linux/grsecurity.h>
60948
60949 #include "internal.h"
60950
60951@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
60952 struct task_struct *task;
60953 struct nsproxy *ns;
60954 struct net *net = NULL;
60955+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60956+ const struct cred *cred = current_cred();
60957+#endif
60958+
60959+#ifdef CONFIG_GRKERNSEC_PROC_USER
60960+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
60961+ return net;
60962+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60963+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
60964+ return net;
60965+#endif
60966
60967 rcu_read_lock();
60968 task = pid_task(proc_pid(dir), PIDTYPE_PID);
60969diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
60970index ac05f33..1e6dc7e 100644
60971--- a/fs/proc/proc_sysctl.c
60972+++ b/fs/proc/proc_sysctl.c
60973@@ -13,11 +13,15 @@
60974 #include <linux/module.h>
60975 #include "internal.h"
60976
60977+extern int gr_handle_chroot_sysctl(const int op);
60978+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
60979+ const int op);
60980+
60981 static const struct dentry_operations proc_sys_dentry_operations;
60982 static const struct file_operations proc_sys_file_operations;
60983-static const struct inode_operations proc_sys_inode_operations;
60984+const struct inode_operations proc_sys_inode_operations;
60985 static const struct file_operations proc_sys_dir_file_operations;
60986-static const struct inode_operations proc_sys_dir_operations;
60987+const struct inode_operations proc_sys_dir_operations;
60988
60989 void proc_sys_poll_notify(struct ctl_table_poll *poll)
60990 {
60991@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
60992
60993 err = NULL;
60994 d_set_d_op(dentry, &proc_sys_dentry_operations);
60995+
60996+ gr_handle_proc_create(dentry, inode);
60997+
60998 d_add(dentry, inode);
60999
61000 out:
61001@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61002 struct inode *inode = file_inode(filp);
61003 struct ctl_table_header *head = grab_header(inode);
61004 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
61005+ int op = write ? MAY_WRITE : MAY_READ;
61006 ssize_t error;
61007 size_t res;
61008
61009@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61010 * and won't be until we finish.
61011 */
61012 error = -EPERM;
61013- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
61014+ if (sysctl_perm(head, table, op))
61015 goto out;
61016
61017 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
61018@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
61019 if (!table->proc_handler)
61020 goto out;
61021
61022+#ifdef CONFIG_GRKERNSEC
61023+ error = -EPERM;
61024+ if (gr_handle_chroot_sysctl(op))
61025+ goto out;
61026+ dget(filp->f_path.dentry);
61027+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
61028+ dput(filp->f_path.dentry);
61029+ goto out;
61030+ }
61031+ dput(filp->f_path.dentry);
61032+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
61033+ goto out;
61034+ if (write && !capable(CAP_SYS_ADMIN))
61035+ goto out;
61036+#endif
61037+
61038 /* careful: calling conventions are nasty here */
61039 res = count;
61040 error = table->proc_handler(table, write, buf, &res, ppos);
61041@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
61042 return -ENOMEM;
61043 } else {
61044 d_set_d_op(child, &proc_sys_dentry_operations);
61045+
61046+ gr_handle_proc_create(child, inode);
61047+
61048 d_add(child, inode);
61049 }
61050 } else {
61051@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
61052 if ((*pos)++ < file->f_pos)
61053 return 0;
61054
61055+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
61056+ return 0;
61057+
61058 if (unlikely(S_ISLNK(table->mode)))
61059 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
61060 else
61061@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
61062 if (IS_ERR(head))
61063 return PTR_ERR(head);
61064
61065+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
61066+ return -ENOENT;
61067+
61068 generic_fillattr(inode, stat);
61069 if (table)
61070 stat->mode = (stat->mode & S_IFMT) | table->mode;
61071@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
61072 .llseek = generic_file_llseek,
61073 };
61074
61075-static const struct inode_operations proc_sys_inode_operations = {
61076+const struct inode_operations proc_sys_inode_operations = {
61077 .permission = proc_sys_permission,
61078 .setattr = proc_sys_setattr,
61079 .getattr = proc_sys_getattr,
61080 };
61081
61082-static const struct inode_operations proc_sys_dir_operations = {
61083+const struct inode_operations proc_sys_dir_operations = {
61084 .lookup = proc_sys_lookup,
61085 .permission = proc_sys_permission,
61086 .setattr = proc_sys_setattr,
61087@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
61088 static struct ctl_dir *new_dir(struct ctl_table_set *set,
61089 const char *name, int namelen)
61090 {
61091- struct ctl_table *table;
61092+ ctl_table_no_const *table;
61093 struct ctl_dir *new;
61094 struct ctl_node *node;
61095 char *new_name;
61096@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
61097 return NULL;
61098
61099 node = (struct ctl_node *)(new + 1);
61100- table = (struct ctl_table *)(node + 1);
61101+ table = (ctl_table_no_const *)(node + 1);
61102 new_name = (char *)(table + 2);
61103 memcpy(new_name, name, namelen);
61104 new_name[namelen] = '\0';
61105@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
61106 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
61107 struct ctl_table_root *link_root)
61108 {
61109- struct ctl_table *link_table, *entry, *link;
61110+ ctl_table_no_const *link_table, *link;
61111+ struct ctl_table *entry;
61112 struct ctl_table_header *links;
61113 struct ctl_node *node;
61114 char *link_name;
61115@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
61116 return NULL;
61117
61118 node = (struct ctl_node *)(links + 1);
61119- link_table = (struct ctl_table *)(node + nr_entries);
61120+ link_table = (ctl_table_no_const *)(node + nr_entries);
61121 link_name = (char *)&link_table[nr_entries + 1];
61122
61123 for (link = link_table, entry = table; entry->procname; link++, entry++) {
61124@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61125 struct ctl_table_header ***subheader, struct ctl_table_set *set,
61126 struct ctl_table *table)
61127 {
61128- struct ctl_table *ctl_table_arg = NULL;
61129- struct ctl_table *entry, *files;
61130+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
61131+ struct ctl_table *entry;
61132 int nr_files = 0;
61133 int nr_dirs = 0;
61134 int err = -ENOMEM;
61135@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61136 nr_files++;
61137 }
61138
61139- files = table;
61140 /* If there are mixed files and directories we need a new table */
61141 if (nr_dirs && nr_files) {
61142- struct ctl_table *new;
61143+ ctl_table_no_const *new;
61144 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
61145 GFP_KERNEL);
61146 if (!files)
61147@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
61148 /* Register everything except a directory full of subdirectories */
61149 if (nr_files || !nr_dirs) {
61150 struct ctl_table_header *header;
61151- header = __register_sysctl_table(set, path, files);
61152+ header = __register_sysctl_table(set, path, files ? files : table);
61153 if (!header) {
61154 kfree(ctl_table_arg);
61155 goto out;
61156diff --git a/fs/proc/root.c b/fs/proc/root.c
61157index 41a6ea9..23eaa92 100644
61158--- a/fs/proc/root.c
61159+++ b/fs/proc/root.c
61160@@ -182,7 +182,15 @@ void __init proc_root_init(void)
61161 #ifdef CONFIG_PROC_DEVICETREE
61162 proc_device_tree_init();
61163 #endif
61164+#ifdef CONFIG_GRKERNSEC_PROC_ADD
61165+#ifdef CONFIG_GRKERNSEC_PROC_USER
61166+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
61167+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61168+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
61169+#endif
61170+#else
61171 proc_mkdir("bus", NULL);
61172+#endif
61173 proc_sys_init();
61174 }
61175
61176diff --git a/fs/proc/self.c b/fs/proc/self.c
61177index 6b6a993..807cccc 100644
61178--- a/fs/proc/self.c
61179+++ b/fs/proc/self.c
61180@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
61181 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
61182 void *cookie)
61183 {
61184- char *s = nd_get_link(nd);
61185+ const char *s = nd_get_link(nd);
61186 if (!IS_ERR(s))
61187 kfree(s);
61188 }
61189diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
61190index 65fc60a..350cc48 100644
61191--- a/fs/proc/task_mmu.c
61192+++ b/fs/proc/task_mmu.c
61193@@ -11,12 +11,19 @@
61194 #include <linux/rmap.h>
61195 #include <linux/swap.h>
61196 #include <linux/swapops.h>
61197+#include <linux/grsecurity.h>
61198
61199 #include <asm/elf.h>
61200 #include <asm/uaccess.h>
61201 #include <asm/tlbflush.h>
61202 #include "internal.h"
61203
61204+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61205+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61206+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
61207+ _mm->pax_flags & MF_PAX_SEGMEXEC))
61208+#endif
61209+
61210 void task_mem(struct seq_file *m, struct mm_struct *mm)
61211 {
61212 unsigned long data, text, lib, swap;
61213@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61214 "VmExe:\t%8lu kB\n"
61215 "VmLib:\t%8lu kB\n"
61216 "VmPTE:\t%8lu kB\n"
61217- "VmSwap:\t%8lu kB\n",
61218- hiwater_vm << (PAGE_SHIFT-10),
61219+ "VmSwap:\t%8lu kB\n"
61220+
61221+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61222+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
61223+#endif
61224+
61225+ ,hiwater_vm << (PAGE_SHIFT-10),
61226 total_vm << (PAGE_SHIFT-10),
61227 mm->locked_vm << (PAGE_SHIFT-10),
61228 mm->pinned_vm << (PAGE_SHIFT-10),
61229@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61230 data << (PAGE_SHIFT-10),
61231 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
61232 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
61233- swap << (PAGE_SHIFT-10));
61234+ swap << (PAGE_SHIFT-10)
61235+
61236+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61237+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61238+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
61239+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
61240+#else
61241+ , mm->context.user_cs_base
61242+ , mm->context.user_cs_limit
61243+#endif
61244+#endif
61245+
61246+ );
61247 }
61248
61249 unsigned long task_vsize(struct mm_struct *mm)
61250@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61251 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
61252 }
61253
61254- /* We don't show the stack guard page in /proc/maps */
61255+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61256+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
61257+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
61258+#else
61259 start = vma->vm_start;
61260- if (stack_guard_page_start(vma, start))
61261- start += PAGE_SIZE;
61262 end = vma->vm_end;
61263- if (stack_guard_page_end(vma, end))
61264- end -= PAGE_SIZE;
61265+#endif
61266
61267 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
61268 start,
61269@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61270 flags & VM_WRITE ? 'w' : '-',
61271 flags & VM_EXEC ? 'x' : '-',
61272 flags & VM_MAYSHARE ? 's' : 'p',
61273+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61274+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
61275+#else
61276 pgoff,
61277+#endif
61278 MAJOR(dev), MINOR(dev), ino, &len);
61279
61280 /*
61281@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61282 */
61283 if (file) {
61284 pad_len_spaces(m, len);
61285- seq_path(m, &file->f_path, "\n");
61286+ seq_path(m, &file->f_path, "\n\\");
61287 goto done;
61288 }
61289
61290@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
61291 * Thread stack in /proc/PID/task/TID/maps or
61292 * the main process stack.
61293 */
61294- if (!is_pid || (vma->vm_start <= mm->start_stack &&
61295- vma->vm_end >= mm->start_stack)) {
61296+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
61297+ (vma->vm_start <= mm->start_stack &&
61298+ vma->vm_end >= mm->start_stack)) {
61299 name = "[stack]";
61300 } else {
61301 /* Thread stack in /proc/PID/maps */
61302@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
61303 struct proc_maps_private *priv = m->private;
61304 struct task_struct *task = priv->task;
61305
61306+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61307+ if (current->exec_id != m->exec_id) {
61308+ gr_log_badprocpid("maps");
61309+ return 0;
61310+ }
61311+#endif
61312+
61313 show_map_vma(m, vma, is_pid);
61314
61315 if (m->count < m->size) /* vma is copied successfully */
61316@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61317 .private = &mss,
61318 };
61319
61320+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61321+ if (current->exec_id != m->exec_id) {
61322+ gr_log_badprocpid("smaps");
61323+ return 0;
61324+ }
61325+#endif
61326 memset(&mss, 0, sizeof mss);
61327- mss.vma = vma;
61328- /* mmap_sem is held in m_start */
61329- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61330- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61331-
61332+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61333+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
61334+#endif
61335+ mss.vma = vma;
61336+ /* mmap_sem is held in m_start */
61337+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
61338+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
61339+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61340+ }
61341+#endif
61342 show_map_vma(m, vma, is_pid);
61343
61344 seq_printf(m,
61345@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
61346 "KernelPageSize: %8lu kB\n"
61347 "MMUPageSize: %8lu kB\n"
61348 "Locked: %8lu kB\n",
61349+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61350+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
61351+#else
61352 (vma->vm_end - vma->vm_start) >> 10,
61353+#endif
61354 mss.resident >> 10,
61355 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
61356 mss.shared_clean >> 10,
61357@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61358 int n;
61359 char buffer[50];
61360
61361+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61362+ if (current->exec_id != m->exec_id) {
61363+ gr_log_badprocpid("numa_maps");
61364+ return 0;
61365+ }
61366+#endif
61367+
61368 if (!mm)
61369 return 0;
61370
61371@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
61372 mpol_to_str(buffer, sizeof(buffer), pol);
61373 mpol_cond_put(pol);
61374
61375+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61376+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
61377+#else
61378 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
61379+#endif
61380
61381 if (file) {
61382 seq_printf(m, " file=");
61383- seq_path(m, &file->f_path, "\n\t= ");
61384+ seq_path(m, &file->f_path, "\n\t\\= ");
61385 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
61386 seq_printf(m, " heap");
61387 } else {
61388diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
61389index 56123a6..5a2f6ec 100644
61390--- a/fs/proc/task_nommu.c
61391+++ b/fs/proc/task_nommu.c
61392@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
61393 else
61394 bytes += kobjsize(mm);
61395
61396- if (current->fs && current->fs->users > 1)
61397+ if (current->fs && atomic_read(&current->fs->users) > 1)
61398 sbytes += kobjsize(current->fs);
61399 else
61400 bytes += kobjsize(current->fs);
61401@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
61402
61403 if (file) {
61404 pad_len_spaces(m, len);
61405- seq_path(m, &file->f_path, "");
61406+ seq_path(m, &file->f_path, "\n\\");
61407 } else if (mm) {
61408 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
61409
61410diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
61411index 17f7e08..e4b1529 100644
61412--- a/fs/proc/vmcore.c
61413+++ b/fs/proc/vmcore.c
61414@@ -99,9 +99,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
61415 nr_bytes = count;
61416
61417 /* If pfn is not ram, return zeros for sparse dump files */
61418- if (pfn_is_ram(pfn) == 0)
61419- memset(buf, 0, nr_bytes);
61420- else {
61421+ if (pfn_is_ram(pfn) == 0) {
61422+ if (userbuf) {
61423+ if (clear_user((char __force_user *)buf, nr_bytes))
61424+ return -EFAULT;
61425+ } else
61426+ memset(buf, 0, nr_bytes);
61427+ } else {
61428 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
61429 offset, userbuf);
61430 if (tmp < 0)
61431@@ -186,7 +190,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
61432 if (tsz > nr_bytes)
61433 tsz = nr_bytes;
61434
61435- tmp = read_from_oldmem(buffer, tsz, &start, 1);
61436+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
61437 if (tmp < 0)
61438 return tmp;
61439 buflen -= tsz;
61440diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
61441index b00fcc9..e0c6381 100644
61442--- a/fs/qnx6/qnx6.h
61443+++ b/fs/qnx6/qnx6.h
61444@@ -74,7 +74,7 @@ enum {
61445 BYTESEX_BE,
61446 };
61447
61448-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61449+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
61450 {
61451 if (sbi->s_bytesex == BYTESEX_LE)
61452 return le64_to_cpu((__force __le64)n);
61453@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
61454 return (__force __fs64)cpu_to_be64(n);
61455 }
61456
61457-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61458+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
61459 {
61460 if (sbi->s_bytesex == BYTESEX_LE)
61461 return le32_to_cpu((__force __le32)n);
61462diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
61463index 16e8abb..2dcf914 100644
61464--- a/fs/quota/netlink.c
61465+++ b/fs/quota/netlink.c
61466@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
61467 void quota_send_warning(struct kqid qid, dev_t dev,
61468 const char warntype)
61469 {
61470- static atomic_t seq;
61471+ static atomic_unchecked_t seq;
61472 struct sk_buff *skb;
61473 void *msg_head;
61474 int ret;
61475@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
61476 "VFS: Not enough memory to send quota warning.\n");
61477 return;
61478 }
61479- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
61480+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
61481 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
61482 if (!msg_head) {
61483 printk(KERN_ERR
61484diff --git a/fs/read_write.c b/fs/read_write.c
61485index 2cefa41..c7e2fe0 100644
61486--- a/fs/read_write.c
61487+++ b/fs/read_write.c
61488@@ -411,7 +411,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
61489
61490 old_fs = get_fs();
61491 set_fs(get_ds());
61492- p = (__force const char __user *)buf;
61493+ p = (const char __force_user *)buf;
61494 if (count > MAX_RW_COUNT)
61495 count = MAX_RW_COUNT;
61496 if (file->f_op->write)
61497diff --git a/fs/readdir.c b/fs/readdir.c
61498index fee38e0..12fdf47 100644
61499--- a/fs/readdir.c
61500+++ b/fs/readdir.c
61501@@ -17,6 +17,7 @@
61502 #include <linux/security.h>
61503 #include <linux/syscalls.h>
61504 #include <linux/unistd.h>
61505+#include <linux/namei.h>
61506
61507 #include <asm/uaccess.h>
61508
61509@@ -67,6 +68,7 @@ struct old_linux_dirent {
61510
61511 struct readdir_callback {
61512 struct old_linux_dirent __user * dirent;
61513+ struct file * file;
61514 int result;
61515 };
61516
61517@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
61518 buf->result = -EOVERFLOW;
61519 return -EOVERFLOW;
61520 }
61521+
61522+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61523+ return 0;
61524+
61525 buf->result++;
61526 dirent = buf->dirent;
61527 if (!access_ok(VERIFY_WRITE, dirent,
61528@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
61529
61530 buf.result = 0;
61531 buf.dirent = dirent;
61532+ buf.file = f.file;
61533
61534 error = vfs_readdir(f.file, fillonedir, &buf);
61535 if (buf.result)
61536@@ -139,6 +146,7 @@ struct linux_dirent {
61537 struct getdents_callback {
61538 struct linux_dirent __user * current_dir;
61539 struct linux_dirent __user * previous;
61540+ struct file * file;
61541 int count;
61542 int error;
61543 };
61544@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
61545 buf->error = -EOVERFLOW;
61546 return -EOVERFLOW;
61547 }
61548+
61549+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61550+ return 0;
61551+
61552 dirent = buf->previous;
61553 if (dirent) {
61554 if (__put_user(offset, &dirent->d_off))
61555@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
61556 buf.previous = NULL;
61557 buf.count = count;
61558 buf.error = 0;
61559+ buf.file = f.file;
61560
61561 error = vfs_readdir(f.file, filldir, &buf);
61562 if (error >= 0)
61563@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
61564 struct getdents_callback64 {
61565 struct linux_dirent64 __user * current_dir;
61566 struct linux_dirent64 __user * previous;
61567+ struct file *file;
61568 int count;
61569 int error;
61570 };
61571@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
61572 buf->error = -EINVAL; /* only used if we fail.. */
61573 if (reclen > buf->count)
61574 return -EINVAL;
61575+
61576+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
61577+ return 0;
61578+
61579 dirent = buf->previous;
61580 if (dirent) {
61581 if (__put_user(offset, &dirent->d_off))
61582@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61583
61584 buf.current_dir = dirent;
61585 buf.previous = NULL;
61586+ buf.file = f.file;
61587 buf.count = count;
61588 buf.error = 0;
61589
61590@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
61591 error = buf.error;
61592 lastdirent = buf.previous;
61593 if (lastdirent) {
61594- typeof(lastdirent->d_off) d_off = f.file->f_pos;
61595+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
61596 if (__put_user(d_off, &lastdirent->d_off))
61597 error = -EFAULT;
61598 else
61599diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
61600index 2b7882b..1c5ef48 100644
61601--- a/fs/reiserfs/do_balan.c
61602+++ b/fs/reiserfs/do_balan.c
61603@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
61604 return;
61605 }
61606
61607- atomic_inc(&(fs_generation(tb->tb_sb)));
61608+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
61609 do_balance_starts(tb);
61610
61611 /* balance leaf returns 0 except if combining L R and S into
61612diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
61613index 1d48974..2f8f4e0 100644
61614--- a/fs/reiserfs/procfs.c
61615+++ b/fs/reiserfs/procfs.c
61616@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
61617 "SMALL_TAILS " : "NO_TAILS ",
61618 replay_only(sb) ? "REPLAY_ONLY " : "",
61619 convert_reiserfs(sb) ? "CONV " : "",
61620- atomic_read(&r->s_generation_counter),
61621+ atomic_read_unchecked(&r->s_generation_counter),
61622 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
61623 SF(s_do_balance), SF(s_unneeded_left_neighbor),
61624 SF(s_good_search_by_key_reada), SF(s_bmaps),
61625diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
61626index 157e474..65a6114 100644
61627--- a/fs/reiserfs/reiserfs.h
61628+++ b/fs/reiserfs/reiserfs.h
61629@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
61630 /* Comment? -Hans */
61631 wait_queue_head_t s_wait;
61632 /* To be obsoleted soon by per buffer seals.. -Hans */
61633- atomic_t s_generation_counter; // increased by one every time the
61634+ atomic_unchecked_t s_generation_counter; // increased by one every time the
61635 // tree gets re-balanced
61636 unsigned long s_properties; /* File system properties. Currently holds
61637 on-disk FS format */
61638@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
61639 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
61640
61641 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
61642-#define get_generation(s) atomic_read (&fs_generation(s))
61643+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
61644 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
61645 #define __fs_changed(gen,s) (gen != get_generation (s))
61646 #define fs_changed(gen,s) \
61647diff --git a/fs/select.c b/fs/select.c
61648index 8c1c96c..a0f9b6d 100644
61649--- a/fs/select.c
61650+++ b/fs/select.c
61651@@ -20,6 +20,7 @@
61652 #include <linux/export.h>
61653 #include <linux/slab.h>
61654 #include <linux/poll.h>
61655+#include <linux/security.h>
61656 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
61657 #include <linux/file.h>
61658 #include <linux/fdtable.h>
61659@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
61660 struct poll_list *walk = head;
61661 unsigned long todo = nfds;
61662
61663+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
61664 if (nfds > rlimit(RLIMIT_NOFILE))
61665 return -EINVAL;
61666
61667diff --git a/fs/seq_file.c b/fs/seq_file.c
61668index 774c1eb..b67582a 100644
61669--- a/fs/seq_file.c
61670+++ b/fs/seq_file.c
61671@@ -10,6 +10,7 @@
61672 #include <linux/seq_file.h>
61673 #include <linux/slab.h>
61674 #include <linux/cred.h>
61675+#include <linux/sched.h>
61676
61677 #include <asm/uaccess.h>
61678 #include <asm/page.h>
61679@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
61680 #ifdef CONFIG_USER_NS
61681 p->user_ns = file->f_cred->user_ns;
61682 #endif
61683+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61684+ p->exec_id = current->exec_id;
61685+#endif
61686
61687 /*
61688 * Wrappers around seq_open(e.g. swaps_open) need to be
61689@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61690 return 0;
61691 }
61692 if (!m->buf) {
61693- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61694+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61695 if (!m->buf)
61696 return -ENOMEM;
61697 }
61698@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
61699 Eoverflow:
61700 m->op->stop(m, p);
61701 kfree(m->buf);
61702- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61703+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61704 return !m->buf ? -ENOMEM : -EAGAIN;
61705 }
61706
61707@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61708
61709 /* grab buffer if we didn't have one */
61710 if (!m->buf) {
61711- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61712+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61713 if (!m->buf)
61714 goto Enomem;
61715 }
61716@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61717 goto Fill;
61718 m->op->stop(m, p);
61719 kfree(m->buf);
61720- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61721+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61722 if (!m->buf)
61723 goto Enomem;
61724 m->count = 0;
61725@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
61726 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
61727 void *data)
61728 {
61729- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
61730+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
61731 int res = -ENOMEM;
61732
61733 if (op) {
61734diff --git a/fs/splice.c b/fs/splice.c
61735index d37431d..81c3044 100644
61736--- a/fs/splice.c
61737+++ b/fs/splice.c
61738@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61739 pipe_lock(pipe);
61740
61741 for (;;) {
61742- if (!pipe->readers) {
61743+ if (!atomic_read(&pipe->readers)) {
61744 send_sig(SIGPIPE, current, 0);
61745 if (!ret)
61746 ret = -EPIPE;
61747@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61748 page_nr++;
61749 ret += buf->len;
61750
61751- if (pipe->files)
61752+ if (atomic_read(&pipe->files))
61753 do_wakeup = 1;
61754
61755 if (!--spd->nr_pages)
61756@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61757 do_wakeup = 0;
61758 }
61759
61760- pipe->waiting_writers++;
61761+ atomic_inc(&pipe->waiting_writers);
61762 pipe_wait(pipe);
61763- pipe->waiting_writers--;
61764+ atomic_dec(&pipe->waiting_writers);
61765 }
61766
61767 pipe_unlock(pipe);
61768@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
61769 old_fs = get_fs();
61770 set_fs(get_ds());
61771 /* The cast to a user pointer is valid due to the set_fs() */
61772- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
61773+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
61774 set_fs(old_fs);
61775
61776 return res;
61777@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
61778 old_fs = get_fs();
61779 set_fs(get_ds());
61780 /* The cast to a user pointer is valid due to the set_fs() */
61781- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
61782+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
61783 set_fs(old_fs);
61784
61785 return res;
61786@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
61787 goto err;
61788
61789 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
61790- vec[i].iov_base = (void __user *) page_address(page);
61791+ vec[i].iov_base = (void __force_user *) page_address(page);
61792 vec[i].iov_len = this_len;
61793 spd.pages[i] = page;
61794 spd.nr_pages++;
61795@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
61796 ops->release(pipe, buf);
61797 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
61798 pipe->nrbufs--;
61799- if (pipe->files)
61800+ if (atomic_read(&pipe->files))
61801 sd->need_wakeup = true;
61802 }
61803
61804@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
61805 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
61806 {
61807 while (!pipe->nrbufs) {
61808- if (!pipe->writers)
61809+ if (!atomic_read(&pipe->writers))
61810 return 0;
61811
61812- if (!pipe->waiting_writers && sd->num_spliced)
61813+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
61814 return 0;
61815
61816 if (sd->flags & SPLICE_F_NONBLOCK)
61817@@ -1193,7 +1193,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
61818 * out of the pipe right after the splice_to_pipe(). So set
61819 * PIPE_READERS appropriately.
61820 */
61821- pipe->readers = 1;
61822+ atomic_set(&pipe->readers, 1);
61823
61824 current->splice_pipe = pipe;
61825 }
61826@@ -1769,9 +1769,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61827 ret = -ERESTARTSYS;
61828 break;
61829 }
61830- if (!pipe->writers)
61831+ if (!atomic_read(&pipe->writers))
61832 break;
61833- if (!pipe->waiting_writers) {
61834+ if (!atomic_read(&pipe->waiting_writers)) {
61835 if (flags & SPLICE_F_NONBLOCK) {
61836 ret = -EAGAIN;
61837 break;
61838@@ -1803,7 +1803,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61839 pipe_lock(pipe);
61840
61841 while (pipe->nrbufs >= pipe->buffers) {
61842- if (!pipe->readers) {
61843+ if (!atomic_read(&pipe->readers)) {
61844 send_sig(SIGPIPE, current, 0);
61845 ret = -EPIPE;
61846 break;
61847@@ -1816,9 +1816,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61848 ret = -ERESTARTSYS;
61849 break;
61850 }
61851- pipe->waiting_writers++;
61852+ atomic_inc(&pipe->waiting_writers);
61853 pipe_wait(pipe);
61854- pipe->waiting_writers--;
61855+ atomic_dec(&pipe->waiting_writers);
61856 }
61857
61858 pipe_unlock(pipe);
61859@@ -1854,14 +1854,14 @@ retry:
61860 pipe_double_lock(ipipe, opipe);
61861
61862 do {
61863- if (!opipe->readers) {
61864+ if (!atomic_read(&opipe->readers)) {
61865 send_sig(SIGPIPE, current, 0);
61866 if (!ret)
61867 ret = -EPIPE;
61868 break;
61869 }
61870
61871- if (!ipipe->nrbufs && !ipipe->writers)
61872+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
61873 break;
61874
61875 /*
61876@@ -1958,7 +1958,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61877 pipe_double_lock(ipipe, opipe);
61878
61879 do {
61880- if (!opipe->readers) {
61881+ if (!atomic_read(&opipe->readers)) {
61882 send_sig(SIGPIPE, current, 0);
61883 if (!ret)
61884 ret = -EPIPE;
61885@@ -2003,7 +2003,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61886 * return EAGAIN if we have the potential of some data in the
61887 * future, otherwise just return 0
61888 */
61889- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
61890+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
61891 ret = -EAGAIN;
61892
61893 pipe_unlock(ipipe);
61894diff --git a/fs/stat.c b/fs/stat.c
61895index 04ce1ac..a13dd1e 100644
61896--- a/fs/stat.c
61897+++ b/fs/stat.c
61898@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
61899 stat->gid = inode->i_gid;
61900 stat->rdev = inode->i_rdev;
61901 stat->size = i_size_read(inode);
61902- stat->atime = inode->i_atime;
61903- stat->mtime = inode->i_mtime;
61904+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61905+ stat->atime = inode->i_ctime;
61906+ stat->mtime = inode->i_ctime;
61907+ } else {
61908+ stat->atime = inode->i_atime;
61909+ stat->mtime = inode->i_mtime;
61910+ }
61911 stat->ctime = inode->i_ctime;
61912 stat->blksize = (1 << inode->i_blkbits);
61913 stat->blocks = inode->i_blocks;
61914@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
61915 if (retval)
61916 return retval;
61917
61918- if (inode->i_op->getattr)
61919- return inode->i_op->getattr(path->mnt, path->dentry, stat);
61920+ if (inode->i_op->getattr) {
61921+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
61922+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61923+ stat->atime = stat->ctime;
61924+ stat->mtime = stat->ctime;
61925+ }
61926+ return retval;
61927+ }
61928
61929 generic_fillattr(inode, stat);
61930 return 0;
61931diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
61932index 15c68f9..36a8b3e 100644
61933--- a/fs/sysfs/bin.c
61934+++ b/fs/sysfs/bin.c
61935@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
61936 return ret;
61937 }
61938
61939-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
61940- void *buf, int len, int write)
61941+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
61942+ void *buf, size_t len, int write)
61943 {
61944 struct file *file = vma->vm_file;
61945 struct bin_buffer *bb = file->private_data;
61946 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
61947- int ret;
61948+ ssize_t ret;
61949
61950 if (!bb->vm_ops)
61951 return -EINVAL;
61952diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
61953index e8e0e71..79c28ac5 100644
61954--- a/fs/sysfs/dir.c
61955+++ b/fs/sysfs/dir.c
61956@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
61957 *
61958 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61959 */
61960-static unsigned int sysfs_name_hash(const void *ns, const char *name)
61961+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
61962 {
61963 unsigned long hash = init_name_hash();
61964 unsigned int len = strlen(name);
61965@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
61966 struct sysfs_dirent *sd;
61967 int rc;
61968
61969+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61970+ const char *parent_name = parent_sd->s_name;
61971+
61972+ mode = S_IFDIR | S_IRWXU;
61973+
61974+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
61975+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
61976+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
61977+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
61978+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
61979+#endif
61980+
61981 /* allocate */
61982 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
61983 if (!sd)
61984diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
61985index 602f56d..6853db8 100644
61986--- a/fs/sysfs/file.c
61987+++ b/fs/sysfs/file.c
61988@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
61989
61990 struct sysfs_open_dirent {
61991 atomic_t refcnt;
61992- atomic_t event;
61993+ atomic_unchecked_t event;
61994 wait_queue_head_t poll;
61995 struct list_head buffers; /* goes through sysfs_buffer.list */
61996 };
61997@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
61998 if (!sysfs_get_active(attr_sd))
61999 return -ENODEV;
62000
62001- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
62002+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
62003 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
62004
62005 sysfs_put_active(attr_sd);
62006@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
62007 return -ENOMEM;
62008
62009 atomic_set(&new_od->refcnt, 0);
62010- atomic_set(&new_od->event, 1);
62011+ atomic_set_unchecked(&new_od->event, 1);
62012 init_waitqueue_head(&new_od->poll);
62013 INIT_LIST_HEAD(&new_od->buffers);
62014 goto retry;
62015@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
62016
62017 sysfs_put_active(attr_sd);
62018
62019- if (buffer->event != atomic_read(&od->event))
62020+ if (buffer->event != atomic_read_unchecked(&od->event))
62021 goto trigger;
62022
62023 return DEFAULT_POLLMASK;
62024@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
62025
62026 od = sd->s_attr.open;
62027 if (od) {
62028- atomic_inc(&od->event);
62029+ atomic_inc_unchecked(&od->event);
62030 wake_up_interruptible(&od->poll);
62031 }
62032
62033diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
62034index 8c940df..25b733e 100644
62035--- a/fs/sysfs/symlink.c
62036+++ b/fs/sysfs/symlink.c
62037@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
62038
62039 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
62040 {
62041- char *page = nd_get_link(nd);
62042+ const char *page = nd_get_link(nd);
62043 if (!IS_ERR(page))
62044 free_page((unsigned long)page);
62045 }
62046diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
62047index 69d4889..a810bd4 100644
62048--- a/fs/sysv/sysv.h
62049+++ b/fs/sysv/sysv.h
62050@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
62051 #endif
62052 }
62053
62054-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62055+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
62056 {
62057 if (sbi->s_bytesex == BYTESEX_PDP)
62058 return PDP_swab((__force __u32)n);
62059diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
62060index e18b988..f1d4ad0f 100644
62061--- a/fs/ubifs/io.c
62062+++ b/fs/ubifs/io.c
62063@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
62064 return err;
62065 }
62066
62067-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62068+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
62069 {
62070 int err;
62071
62072diff --git a/fs/udf/misc.c b/fs/udf/misc.c
62073index c175b4d..8f36a16 100644
62074--- a/fs/udf/misc.c
62075+++ b/fs/udf/misc.c
62076@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
62077
62078 u8 udf_tag_checksum(const struct tag *t)
62079 {
62080- u8 *data = (u8 *)t;
62081+ const u8 *data = (const u8 *)t;
62082 u8 checksum = 0;
62083 int i;
62084 for (i = 0; i < sizeof(struct tag); ++i)
62085diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
62086index 8d974c4..b82f6ec 100644
62087--- a/fs/ufs/swab.h
62088+++ b/fs/ufs/swab.h
62089@@ -22,7 +22,7 @@ enum {
62090 BYTESEX_BE
62091 };
62092
62093-static inline u64
62094+static inline u64 __intentional_overflow(-1)
62095 fs64_to_cpu(struct super_block *sbp, __fs64 n)
62096 {
62097 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62098@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
62099 return (__force __fs64)cpu_to_be64(n);
62100 }
62101
62102-static inline u32
62103+static inline u32 __intentional_overflow(-1)
62104 fs32_to_cpu(struct super_block *sbp, __fs32 n)
62105 {
62106 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
62107diff --git a/fs/utimes.c b/fs/utimes.c
62108index f4fb7ec..3fe03c0 100644
62109--- a/fs/utimes.c
62110+++ b/fs/utimes.c
62111@@ -1,6 +1,7 @@
62112 #include <linux/compiler.h>
62113 #include <linux/file.h>
62114 #include <linux/fs.h>
62115+#include <linux/security.h>
62116 #include <linux/linkage.h>
62117 #include <linux/mount.h>
62118 #include <linux/namei.h>
62119@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
62120 goto mnt_drop_write_and_out;
62121 }
62122 }
62123+
62124+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
62125+ error = -EACCES;
62126+ goto mnt_drop_write_and_out;
62127+ }
62128+
62129 mutex_lock(&inode->i_mutex);
62130 error = notify_change(path->dentry, &newattrs);
62131 mutex_unlock(&inode->i_mutex);
62132diff --git a/fs/xattr.c b/fs/xattr.c
62133index 3377dff..4d074d9 100644
62134--- a/fs/xattr.c
62135+++ b/fs/xattr.c
62136@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
62137 return rc;
62138 }
62139
62140+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
62141+ssize_t
62142+pax_getxattr(struct dentry *dentry, void *value, size_t size)
62143+{
62144+ struct inode *inode = dentry->d_inode;
62145+ ssize_t error;
62146+
62147+ error = inode_permission(inode, MAY_EXEC);
62148+ if (error)
62149+ return error;
62150+
62151+ if (inode->i_op->getxattr)
62152+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
62153+ else
62154+ error = -EOPNOTSUPP;
62155+
62156+ return error;
62157+}
62158+EXPORT_SYMBOL(pax_getxattr);
62159+#endif
62160+
62161 ssize_t
62162 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
62163 {
62164@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
62165 * Extended attribute SET operations
62166 */
62167 static long
62168-setxattr(struct dentry *d, const char __user *name, const void __user *value,
62169+setxattr(struct path *path, const char __user *name, const void __user *value,
62170 size_t size, int flags)
62171 {
62172 int error;
62173@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
62174 posix_acl_fix_xattr_from_user(kvalue, size);
62175 }
62176
62177- error = vfs_setxattr(d, kname, kvalue, size, flags);
62178+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
62179+ error = -EACCES;
62180+ goto out;
62181+ }
62182+
62183+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
62184 out:
62185 if (vvalue)
62186 vfree(vvalue);
62187@@ -377,7 +403,7 @@ retry:
62188 return error;
62189 error = mnt_want_write(path.mnt);
62190 if (!error) {
62191- error = setxattr(path.dentry, name, value, size, flags);
62192+ error = setxattr(&path, name, value, size, flags);
62193 mnt_drop_write(path.mnt);
62194 }
62195 path_put(&path);
62196@@ -401,7 +427,7 @@ retry:
62197 return error;
62198 error = mnt_want_write(path.mnt);
62199 if (!error) {
62200- error = setxattr(path.dentry, name, value, size, flags);
62201+ error = setxattr(&path, name, value, size, flags);
62202 mnt_drop_write(path.mnt);
62203 }
62204 path_put(&path);
62205@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
62206 const void __user *,value, size_t, size, int, flags)
62207 {
62208 struct fd f = fdget(fd);
62209- struct dentry *dentry;
62210 int error = -EBADF;
62211
62212 if (!f.file)
62213 return error;
62214- dentry = f.file->f_path.dentry;
62215- audit_inode(NULL, dentry, 0);
62216+ audit_inode(NULL, f.file->f_path.dentry, 0);
62217 error = mnt_want_write_file(f.file);
62218 if (!error) {
62219- error = setxattr(dentry, name, value, size, flags);
62220+ error = setxattr(&f.file->f_path, name, value, size, flags);
62221 mnt_drop_write_file(f.file);
62222 }
62223 fdput(f);
62224diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
62225index 9fbea87..6b19972 100644
62226--- a/fs/xattr_acl.c
62227+++ b/fs/xattr_acl.c
62228@@ -76,8 +76,8 @@ struct posix_acl *
62229 posix_acl_from_xattr(struct user_namespace *user_ns,
62230 const void *value, size_t size)
62231 {
62232- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62233- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62234+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62235+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62236 int count;
62237 struct posix_acl *acl;
62238 struct posix_acl_entry *acl_e;
62239diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
62240index 8904284..ee0e14b 100644
62241--- a/fs/xfs/xfs_bmap.c
62242+++ b/fs/xfs/xfs_bmap.c
62243@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
62244
62245 #else
62246 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
62247-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
62248+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
62249 #endif /* DEBUG */
62250
62251 /*
62252diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
62253index 6157424..ac98f6d 100644
62254--- a/fs/xfs/xfs_dir2_sf.c
62255+++ b/fs/xfs/xfs_dir2_sf.c
62256@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
62257 }
62258
62259 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
62260- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
62261+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
62262+ char name[sfep->namelen];
62263+ memcpy(name, sfep->name, sfep->namelen);
62264+ if (filldir(dirent, name, sfep->namelen,
62265+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
62266+ *offset = off & 0x7fffffff;
62267+ return 0;
62268+ }
62269+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
62270 off & 0x7fffffff, ino, DT_UNKNOWN)) {
62271 *offset = off & 0x7fffffff;
62272 return 0;
62273diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
62274index 5e99968..45bd327 100644
62275--- a/fs/xfs/xfs_ioctl.c
62276+++ b/fs/xfs/xfs_ioctl.c
62277@@ -127,7 +127,7 @@ xfs_find_handle(
62278 }
62279
62280 error = -EFAULT;
62281- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
62282+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
62283 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
62284 goto out_put;
62285
62286diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
62287index ca9ecaa..60100c7 100644
62288--- a/fs/xfs/xfs_iops.c
62289+++ b/fs/xfs/xfs_iops.c
62290@@ -395,7 +395,7 @@ xfs_vn_put_link(
62291 struct nameidata *nd,
62292 void *p)
62293 {
62294- char *s = nd_get_link(nd);
62295+ const char *s = nd_get_link(nd);
62296
62297 if (!IS_ERR(s))
62298 kfree(s);
62299diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
62300new file mode 100644
62301index 0000000..6fb5192
62302--- /dev/null
62303+++ b/grsecurity/Kconfig
62304@@ -0,0 +1,1079 @@
62305+#
62306+# grecurity configuration
62307+#
62308+menu "Memory Protections"
62309+depends on GRKERNSEC
62310+
62311+config GRKERNSEC_KMEM
62312+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
62313+ default y if GRKERNSEC_CONFIG_AUTO
62314+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
62315+ help
62316+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
62317+ be written to or read from to modify or leak the contents of the running
62318+ kernel. /dev/port will also not be allowed to be opened and support
62319+ for /dev/cpu/*/msr will be removed. If you have module
62320+ support disabled, enabling this will close up five ways that are
62321+ currently used to insert malicious code into the running kernel.
62322+
62323+ Even with all these features enabled, we still highly recommend that
62324+ you use the RBAC system, as it is still possible for an attacker to
62325+ modify the running kernel through privileged I/O granted by ioperm/iopl.
62326+
62327+ If you are not using XFree86, you may be able to stop this additional
62328+ case by enabling the 'Disable privileged I/O' option. Though nothing
62329+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
62330+ but only to video memory, which is the only writing we allow in this
62331+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
62332+ not be allowed to mprotect it with PROT_WRITE later.
62333+ Enabling this feature will prevent the "cpupower" and "powertop" tools
62334+ from working.
62335+
62336+ It is highly recommended that you say Y here if you meet all the
62337+ conditions above.
62338+
62339+config GRKERNSEC_VM86
62340+ bool "Restrict VM86 mode"
62341+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62342+ depends on X86_32
62343+
62344+ help
62345+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
62346+ make use of a special execution mode on 32bit x86 processors called
62347+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
62348+ video cards and will still work with this option enabled. The purpose
62349+ of the option is to prevent exploitation of emulation errors in
62350+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
62351+ Nearly all users should be able to enable this option.
62352+
62353+config GRKERNSEC_IO
62354+ bool "Disable privileged I/O"
62355+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62356+ depends on X86
62357+ select RTC_CLASS
62358+ select RTC_INTF_DEV
62359+ select RTC_DRV_CMOS
62360+
62361+ help
62362+ If you say Y here, all ioperm and iopl calls will return an error.
62363+ Ioperm and iopl can be used to modify the running kernel.
62364+ Unfortunately, some programs need this access to operate properly,
62365+ the most notable of which are XFree86 and hwclock. hwclock can be
62366+ remedied by having RTC support in the kernel, so real-time
62367+ clock support is enabled if this option is enabled, to ensure
62368+ that hwclock operates correctly. XFree86 still will not
62369+ operate correctly with this option enabled, so DO NOT CHOOSE Y
62370+ IF YOU USE XFree86. If you use XFree86 and you still want to
62371+ protect your kernel against modification, use the RBAC system.
62372+
62373+config GRKERNSEC_JIT_HARDEN
62374+ bool "Harden BPF JIT against spray attacks"
62375+ default y if GRKERNSEC_CONFIG_AUTO
62376+ depends on BPF_JIT
62377+ help
62378+ If you say Y here, the native code generated by the kernel's Berkeley
62379+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
62380+ attacks that attempt to fit attacker-beneficial instructions in
62381+ 32bit immediate fields of JIT-generated native instructions. The
62382+ attacker will generally aim to cause an unintended instruction sequence
62383+ of JIT-generated native code to execute by jumping into the middle of
62384+ a generated instruction. This feature effectively randomizes the 32bit
62385+ immediate constants present in the generated code to thwart such attacks.
62386+
62387+ If you're using KERNEXEC, it's recommended that you enable this option
62388+ to supplement the hardening of the kernel.
62389+
62390+config GRKERNSEC_PERF_HARDEN
62391+ bool "Disable unprivileged PERF_EVENTS usage by default"
62392+ default y if GRKERNSEC_CONFIG_AUTO
62393+ depends on PERF_EVENTS
62394+ help
62395+ If you say Y here, the range of acceptable values for the
62396+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
62397+ default to a new value: 3. When the sysctl is set to this value, no
62398+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
62399+
62400+ Though PERF_EVENTS can be used legitimately for performance monitoring
62401+ and low-level application profiling, it is forced on regardless of
62402+ configuration, has been at fault for several vulnerabilities, and
62403+ creates new opportunities for side channels and other information leaks.
62404+
62405+ This feature puts PERF_EVENTS into a secure default state and permits
62406+ the administrator to change out of it temporarily if unprivileged
62407+ application profiling is needed.
62408+
62409+config GRKERNSEC_RAND_THREADSTACK
62410+ bool "Insert random gaps between thread stacks"
62411+ default y if GRKERNSEC_CONFIG_AUTO
62412+ depends on PAX_RANDMMAP && !PPC
62413+ help
62414+ If you say Y here, a random-sized gap will be enforced between allocated
62415+ thread stacks. Glibc's NPTL and other threading libraries that
62416+ pass MAP_STACK to the kernel for thread stack allocation are supported.
62417+ The implementation currently provides 8 bits of entropy for the gap.
62418+
62419+ Many distributions do not compile threaded remote services with the
62420+ -fstack-check argument to GCC, causing the variable-sized stack-based
62421+ allocator, alloca(), to not probe the stack on allocation. This
62422+ permits an unbounded alloca() to skip over any guard page and potentially
62423+ modify another thread's stack reliably. An enforced random gap
62424+ reduces the reliability of such an attack and increases the chance
62425+ that such a read/write to another thread's stack instead lands in
62426+ an unmapped area, causing a crash and triggering grsecurity's
62427+ anti-bruteforcing logic.
62428+
62429+config GRKERNSEC_PROC_MEMMAP
62430+ bool "Harden ASLR against information leaks and entropy reduction"
62431+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
62432+ depends on PAX_NOEXEC || PAX_ASLR
62433+ help
62434+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
62435+ give no information about the addresses of its mappings if
62436+ PaX features that rely on random addresses are enabled on the task.
62437+ In addition to sanitizing this information and disabling other
62438+ dangerous sources of information, this option causes reads of sensitive
62439+ /proc/<pid> entries where the file descriptor was opened in a different
62440+ task than the one performing the read. Such attempts are logged.
62441+ This option also limits argv/env strings for suid/sgid binaries
62442+ to 512KB to prevent a complete exhaustion of the stack entropy provided
62443+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
62444+ binaries to prevent alternative mmap layouts from being abused.
62445+
62446+ If you use PaX it is essential that you say Y here as it closes up
62447+ several holes that make full ASLR useless locally.
62448+
62449+config GRKERNSEC_BRUTE
62450+ bool "Deter exploit bruteforcing"
62451+ default y if GRKERNSEC_CONFIG_AUTO
62452+ help
62453+ If you say Y here, attempts to bruteforce exploits against forking
62454+ daemons such as apache or sshd, as well as against suid/sgid binaries
62455+ will be deterred. When a child of a forking daemon is killed by PaX
62456+ or crashes due to an illegal instruction or other suspicious signal,
62457+ the parent process will be delayed 30 seconds upon every subsequent
62458+ fork until the administrator is able to assess the situation and
62459+ restart the daemon.
62460+ In the suid/sgid case, the attempt is logged, the user has all their
62461+ existing instances of the suid/sgid binary terminated and will
62462+ be unable to execute any suid/sgid binaries for 15 minutes.
62463+
62464+ It is recommended that you also enable signal logging in the auditing
62465+ section so that logs are generated when a process triggers a suspicious
62466+ signal.
62467+ If the sysctl option is enabled, a sysctl option with name
62468+ "deter_bruteforce" is created.
62469+
62470+
62471+config GRKERNSEC_MODHARDEN
62472+ bool "Harden module auto-loading"
62473+ default y if GRKERNSEC_CONFIG_AUTO
62474+ depends on MODULES
62475+ help
62476+ If you say Y here, module auto-loading in response to use of some
62477+ feature implemented by an unloaded module will be restricted to
62478+ root users. Enabling this option helps defend against attacks
62479+ by unprivileged users who abuse the auto-loading behavior to
62480+ cause a vulnerable module to load that is then exploited.
62481+
62482+ If this option prevents a legitimate use of auto-loading for a
62483+ non-root user, the administrator can execute modprobe manually
62484+ with the exact name of the module mentioned in the alert log.
62485+ Alternatively, the administrator can add the module to the list
62486+ of modules loaded at boot by modifying init scripts.
62487+
62488+ Modification of init scripts will most likely be needed on
62489+ Ubuntu servers with encrypted home directory support enabled,
62490+ as the first non-root user logging in will cause the ecb(aes),
62491+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
62492+
62493+config GRKERNSEC_HIDESYM
62494+ bool "Hide kernel symbols"
62495+ default y if GRKERNSEC_CONFIG_AUTO
62496+ select PAX_USERCOPY_SLABS
62497+ help
62498+ If you say Y here, getting information on loaded modules, and
62499+ displaying all kernel symbols through a syscall will be restricted
62500+ to users with CAP_SYS_MODULE. For software compatibility reasons,
62501+ /proc/kallsyms will be restricted to the root user. The RBAC
62502+ system can hide that entry even from root.
62503+
62504+ This option also prevents leaking of kernel addresses through
62505+ several /proc entries.
62506+
62507+ Note that this option is only effective provided the following
62508+ conditions are met:
62509+ 1) The kernel using grsecurity is not precompiled by some distribution
62510+ 2) You have also enabled GRKERNSEC_DMESG
62511+ 3) You are using the RBAC system and hiding other files such as your
62512+ kernel image and System.map. Alternatively, enabling this option
62513+ causes the permissions on /boot, /lib/modules, and the kernel
62514+ source directory to change at compile time to prevent
62515+ reading by non-root users.
62516+ If the above conditions are met, this option will aid in providing a
62517+ useful protection against local kernel exploitation of overflows
62518+ and arbitrary read/write vulnerabilities.
62519+
62520+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
62521+ in addition to this feature.
62522+
62523+config GRKERNSEC_KERN_LOCKOUT
62524+ bool "Active kernel exploit response"
62525+ default y if GRKERNSEC_CONFIG_AUTO
62526+ depends on X86 || ARM || PPC || SPARC
62527+ help
62528+ If you say Y here, when a PaX alert is triggered due to suspicious
62529+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
62530+ or an OOPS occurs due to bad memory accesses, instead of just
62531+ terminating the offending process (and potentially allowing
62532+ a subsequent exploit from the same user), we will take one of two
62533+ actions:
62534+ If the user was root, we will panic the system
62535+ If the user was non-root, we will log the attempt, terminate
62536+ all processes owned by the user, then prevent them from creating
62537+ any new processes until the system is restarted
62538+ This deters repeated kernel exploitation/bruteforcing attempts
62539+ and is useful for later forensics.
62540+
62541+endmenu
62542+menu "Role Based Access Control Options"
62543+depends on GRKERNSEC
62544+
62545+config GRKERNSEC_RBAC_DEBUG
62546+ bool
62547+
62548+config GRKERNSEC_NO_RBAC
62549+ bool "Disable RBAC system"
62550+ help
62551+ If you say Y here, the /dev/grsec device will be removed from the kernel,
62552+ preventing the RBAC system from being enabled. You should only say Y
62553+ here if you have no intention of using the RBAC system, so as to prevent
62554+ an attacker with root access from misusing the RBAC system to hide files
62555+ and processes when loadable module support and /dev/[k]mem have been
62556+ locked down.
62557+
62558+config GRKERNSEC_ACL_HIDEKERN
62559+ bool "Hide kernel processes"
62560+ help
62561+ If you say Y here, all kernel threads will be hidden to all
62562+ processes but those whose subject has the "view hidden processes"
62563+ flag.
62564+
62565+config GRKERNSEC_ACL_MAXTRIES
62566+ int "Maximum tries before password lockout"
62567+ default 3
62568+ help
62569+ This option enforces the maximum number of times a user can attempt
62570+ to authorize themselves with the grsecurity RBAC system before being
62571+ denied the ability to attempt authorization again for a specified time.
62572+ The lower the number, the harder it will be to brute-force a password.
62573+
62574+config GRKERNSEC_ACL_TIMEOUT
62575+ int "Time to wait after max password tries, in seconds"
62576+ default 30
62577+ help
62578+ This option specifies the time the user must wait after attempting to
62579+ authorize to the RBAC system with the maximum number of invalid
62580+ passwords. The higher the number, the harder it will be to brute-force
62581+ a password.
62582+
62583+endmenu
62584+menu "Filesystem Protections"
62585+depends on GRKERNSEC
62586+
62587+config GRKERNSEC_PROC
62588+ bool "Proc restrictions"
62589+ default y if GRKERNSEC_CONFIG_AUTO
62590+ help
62591+ If you say Y here, the permissions of the /proc filesystem
62592+ will be altered to enhance system security and privacy. You MUST
62593+ choose either a user only restriction or a user and group restriction.
62594+ Depending upon the option you choose, you can either restrict users to
62595+ see only the processes they themselves run, or choose a group that can
62596+ view all processes and files normally restricted to root if you choose
62597+ the "restrict to user only" option. NOTE: If you're running identd or
62598+ ntpd as a non-root user, you will have to run it as the group you
62599+ specify here.
62600+
62601+config GRKERNSEC_PROC_USER
62602+ bool "Restrict /proc to user only"
62603+ depends on GRKERNSEC_PROC
62604+ help
62605+ If you say Y here, non-root users will only be able to view their own
62606+ processes, and restricts them from viewing network-related information,
62607+ and viewing kernel symbol and module information.
62608+
62609+config GRKERNSEC_PROC_USERGROUP
62610+ bool "Allow special group"
62611+ default y if GRKERNSEC_CONFIG_AUTO
62612+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
62613+ help
62614+ If you say Y here, you will be able to select a group that will be
62615+ able to view all processes and network-related information. If you've
62616+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
62617+ remain hidden. This option is useful if you want to run identd as
62618+ a non-root user. The group you select may also be chosen at boot time
62619+ via "grsec_proc_gid=" on the kernel commandline.
62620+
62621+config GRKERNSEC_PROC_GID
62622+ int "GID for special group"
62623+ depends on GRKERNSEC_PROC_USERGROUP
62624+ default 1001
62625+
62626+config GRKERNSEC_PROC_ADD
62627+ bool "Additional restrictions"
62628+ default y if GRKERNSEC_CONFIG_AUTO
62629+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
62630+ help
62631+ If you say Y here, additional restrictions will be placed on
62632+ /proc that keep normal users from viewing device information and
62633+ slabinfo information that could be useful for exploits.
62634+
62635+config GRKERNSEC_LINK
62636+ bool "Linking restrictions"
62637+ default y if GRKERNSEC_CONFIG_AUTO
62638+ help
62639+ If you say Y here, /tmp race exploits will be prevented, since users
62640+ will no longer be able to follow symlinks owned by other users in
62641+ world-writable +t directories (e.g. /tmp), unless the owner of the
62642+ symlink is the owner of the directory. users will also not be
62643+ able to hardlink to files they do not own. If the sysctl option is
62644+ enabled, a sysctl option with name "linking_restrictions" is created.
62645+
62646+config GRKERNSEC_SYMLINKOWN
62647+ bool "Kernel-enforced SymlinksIfOwnerMatch"
62648+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
62649+ help
62650+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
62651+ that prevents it from being used as a security feature. As Apache
62652+ verifies the symlink by performing a stat() against the target of
62653+ the symlink before it is followed, an attacker can setup a symlink
62654+ to point to a same-owned file, then replace the symlink with one
62655+ that targets another user's file just after Apache "validates" the
62656+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
62657+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
62658+ will be in place for the group you specify. If the sysctl option
62659+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
62660+ created.
62661+
62662+config GRKERNSEC_SYMLINKOWN_GID
62663+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
62664+ depends on GRKERNSEC_SYMLINKOWN
62665+ default 1006
62666+ help
62667+ Setting this GID determines what group kernel-enforced
62668+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
62669+ is enabled, a sysctl option with name "symlinkown_gid" is created.
62670+
62671+config GRKERNSEC_FIFO
62672+ bool "FIFO restrictions"
62673+ default y if GRKERNSEC_CONFIG_AUTO
62674+ help
62675+ If you say Y here, users will not be able to write to FIFOs they don't
62676+ own in world-writable +t directories (e.g. /tmp), unless the owner of
62677+ the FIFO is the same owner of the directory it's held in. If the sysctl
62678+ option is enabled, a sysctl option with name "fifo_restrictions" is
62679+ created.
62680+
62681+config GRKERNSEC_SYSFS_RESTRICT
62682+ bool "Sysfs/debugfs restriction"
62683+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
62684+ depends on SYSFS
62685+ help
62686+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
62687+ any filesystem normally mounted under it (e.g. debugfs) will be
62688+ mostly accessible only by root. These filesystems generally provide access
62689+ to hardware and debug information that isn't appropriate for unprivileged
62690+ users of the system. Sysfs and debugfs have also become a large source
62691+ of new vulnerabilities, ranging from infoleaks to local compromise.
62692+ There has been very little oversight with an eye toward security involved
62693+ in adding new exporters of information to these filesystems, so their
62694+ use is discouraged.
62695+ For reasons of compatibility, a few directories have been whitelisted
62696+ for access by non-root users:
62697+ /sys/fs/selinux
62698+ /sys/fs/fuse
62699+ /sys/devices/system/cpu
62700+
62701+config GRKERNSEC_ROFS
62702+ bool "Runtime read-only mount protection"
62703+ depends on SYSCTL
62704+ help
62705+ If you say Y here, a sysctl option with name "romount_protect" will
62706+ be created. By setting this option to 1 at runtime, filesystems
62707+ will be protected in the following ways:
62708+ * No new writable mounts will be allowed
62709+ * Existing read-only mounts won't be able to be remounted read/write
62710+ * Write operations will be denied on all block devices
62711+ This option acts independently of grsec_lock: once it is set to 1,
62712+ it cannot be turned off. Therefore, please be mindful of the resulting
62713+ behavior if this option is enabled in an init script on a read-only
62714+ filesystem. This feature is mainly intended for secure embedded systems.
62715+
62716+config GRKERNSEC_DEVICE_SIDECHANNEL
62717+ bool "Eliminate stat/notify-based device sidechannels"
62718+ default y if GRKERNSEC_CONFIG_AUTO
62719+ help
62720+ If you say Y here, timing analyses on block or character
62721+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
62722+ will be thwarted for unprivileged users. If a process without
62723+ CAP_MKNOD stats such a device, the last access and last modify times
62724+ will match the device's create time. No access or modify events
62725+ will be triggered through inotify/dnotify/fanotify for such devices.
62726+ This feature will prevent attacks that may at a minimum
62727+ allow an attacker to determine the administrator's password length.
62728+
62729+config GRKERNSEC_CHROOT
62730+ bool "Chroot jail restrictions"
62731+ default y if GRKERNSEC_CONFIG_AUTO
62732+ help
62733+ If you say Y here, you will be able to choose several options that will
62734+ make breaking out of a chrooted jail much more difficult. If you
62735+ encounter no software incompatibilities with the following options, it
62736+ is recommended that you enable each one.
62737+
62738+config GRKERNSEC_CHROOT_MOUNT
62739+ bool "Deny mounts"
62740+ default y if GRKERNSEC_CONFIG_AUTO
62741+ depends on GRKERNSEC_CHROOT
62742+ help
62743+ If you say Y here, processes inside a chroot will not be able to
62744+ mount or remount filesystems. If the sysctl option is enabled, a
62745+ sysctl option with name "chroot_deny_mount" is created.
62746+
62747+config GRKERNSEC_CHROOT_DOUBLE
62748+ bool "Deny double-chroots"
62749+ default y if GRKERNSEC_CONFIG_AUTO
62750+ depends on GRKERNSEC_CHROOT
62751+ help
62752+ If you say Y here, processes inside a chroot will not be able to chroot
62753+ again outside the chroot. This is a widely used method of breaking
62754+ out of a chroot jail and should not be allowed. If the sysctl
62755+ option is enabled, a sysctl option with name
62756+ "chroot_deny_chroot" is created.
62757+
62758+config GRKERNSEC_CHROOT_PIVOT
62759+ bool "Deny pivot_root in chroot"
62760+ default y if GRKERNSEC_CONFIG_AUTO
62761+ depends on GRKERNSEC_CHROOT
62762+ help
62763+ If you say Y here, processes inside a chroot will not be able to use
62764+ a function called pivot_root() that was introduced in Linux 2.3.41. It
62765+ works similar to chroot in that it changes the root filesystem. This
62766+ function could be misused in a chrooted process to attempt to break out
62767+ of the chroot, and therefore should not be allowed. If the sysctl
62768+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
62769+ created.
62770+
62771+config GRKERNSEC_CHROOT_CHDIR
62772+ bool "Enforce chdir(\"/\") on all chroots"
62773+ default y if GRKERNSEC_CONFIG_AUTO
62774+ depends on GRKERNSEC_CHROOT
62775+ help
62776+ If you say Y here, the current working directory of all newly-chrooted
62777+ applications will be set to the the root directory of the chroot.
62778+ The man page on chroot(2) states:
62779+ Note that this call does not change the current working
62780+ directory, so that `.' can be outside the tree rooted at
62781+ `/'. In particular, the super-user can escape from a
62782+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
62783+
62784+ It is recommended that you say Y here, since it's not known to break
62785+ any software. If the sysctl option is enabled, a sysctl option with
62786+ name "chroot_enforce_chdir" is created.
62787+
62788+config GRKERNSEC_CHROOT_CHMOD
62789+ bool "Deny (f)chmod +s"
62790+ default y if GRKERNSEC_CONFIG_AUTO
62791+ depends on GRKERNSEC_CHROOT
62792+ help
62793+ If you say Y here, processes inside a chroot will not be able to chmod
62794+ or fchmod files to make them have suid or sgid bits. This protects
62795+ against another published method of breaking a chroot. If the sysctl
62796+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
62797+ created.
62798+
62799+config GRKERNSEC_CHROOT_FCHDIR
62800+ bool "Deny fchdir out of chroot"
62801+ default y if GRKERNSEC_CONFIG_AUTO
62802+ depends on GRKERNSEC_CHROOT
62803+ help
62804+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
62805+ to a file descriptor of the chrooting process that points to a directory
62806+ outside the filesystem will be stopped. If the sysctl option
62807+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
62808+
62809+config GRKERNSEC_CHROOT_MKNOD
62810+ bool "Deny mknod"
62811+ default y if GRKERNSEC_CONFIG_AUTO
62812+ depends on GRKERNSEC_CHROOT
62813+ help
62814+ If you say Y here, processes inside a chroot will not be allowed to
62815+ mknod. The problem with using mknod inside a chroot is that it
62816+ would allow an attacker to create a device entry that is the same
62817+ as one on the physical root of your system, which could range from
62818+ anything from the console device to a device for your harddrive (which
62819+ they could then use to wipe the drive or steal data). It is recommended
62820+ that you say Y here, unless you run into software incompatibilities.
62821+ If the sysctl option is enabled, a sysctl option with name
62822+ "chroot_deny_mknod" is created.
62823+
62824+config GRKERNSEC_CHROOT_SHMAT
62825+ bool "Deny shmat() out of chroot"
62826+ default y if GRKERNSEC_CONFIG_AUTO
62827+ depends on GRKERNSEC_CHROOT
62828+ help
62829+ If you say Y here, processes inside a chroot will not be able to attach
62830+ to shared memory segments that were created outside of the chroot jail.
62831+ It is recommended that you say Y here. If the sysctl option is enabled,
62832+ a sysctl option with name "chroot_deny_shmat" is created.
62833+
62834+config GRKERNSEC_CHROOT_UNIX
62835+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
62836+ default y if GRKERNSEC_CONFIG_AUTO
62837+ depends on GRKERNSEC_CHROOT
62838+ help
62839+ If you say Y here, processes inside a chroot will not be able to
62840+ connect to abstract (meaning not belonging to a filesystem) Unix
62841+ domain sockets that were bound outside of a chroot. It is recommended
62842+ that you say Y here. If the sysctl option is enabled, a sysctl option
62843+ with name "chroot_deny_unix" is created.
62844+
62845+config GRKERNSEC_CHROOT_FINDTASK
62846+ bool "Protect outside processes"
62847+ default y if GRKERNSEC_CONFIG_AUTO
62848+ depends on GRKERNSEC_CHROOT
62849+ help
62850+ If you say Y here, processes inside a chroot will not be able to
62851+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
62852+ getsid, or view any process outside of the chroot. If the sysctl
62853+ option is enabled, a sysctl option with name "chroot_findtask" is
62854+ created.
62855+
62856+config GRKERNSEC_CHROOT_NICE
62857+ bool "Restrict priority changes"
62858+ default y if GRKERNSEC_CONFIG_AUTO
62859+ depends on GRKERNSEC_CHROOT
62860+ help
62861+ If you say Y here, processes inside a chroot will not be able to raise
62862+ the priority of processes in the chroot, or alter the priority of
62863+ processes outside the chroot. This provides more security than simply
62864+ removing CAP_SYS_NICE from the process' capability set. If the
62865+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
62866+ is created.
62867+
62868+config GRKERNSEC_CHROOT_SYSCTL
62869+ bool "Deny sysctl writes"
62870+ default y if GRKERNSEC_CONFIG_AUTO
62871+ depends on GRKERNSEC_CHROOT
62872+ help
62873+ If you say Y here, an attacker in a chroot will not be able to
62874+ write to sysctl entries, either by sysctl(2) or through a /proc
62875+ interface. It is strongly recommended that you say Y here. If the
62876+ sysctl option is enabled, a sysctl option with name
62877+ "chroot_deny_sysctl" is created.
62878+
62879+config GRKERNSEC_CHROOT_CAPS
62880+ bool "Capability restrictions"
62881+ default y if GRKERNSEC_CONFIG_AUTO
62882+ depends on GRKERNSEC_CHROOT
62883+ help
62884+ If you say Y here, the capabilities on all processes within a
62885+ chroot jail will be lowered to stop module insertion, raw i/o,
62886+ system and net admin tasks, rebooting the system, modifying immutable
62887+ files, modifying IPC owned by another, and changing the system time.
62888+ This is left an option because it can break some apps. Disable this
62889+ if your chrooted apps are having problems performing those kinds of
62890+ tasks. If the sysctl option is enabled, a sysctl option with
62891+ name "chroot_caps" is created.
62892+
62893+config GRKERNSEC_CHROOT_INITRD
62894+ bool "Exempt initrd tasks from restrictions"
62895+ default y if GRKERNSEC_CONFIG_AUTO
62896+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
62897+ help
62898+ If you say Y here, tasks started prior to init will be exempted from
62899+ grsecurity's chroot restrictions. This option is mainly meant to
62900+ resolve Plymouth's performing privileged operations unnecessarily
62901+ in a chroot.
62902+
62903+endmenu
62904+menu "Kernel Auditing"
62905+depends on GRKERNSEC
62906+
62907+config GRKERNSEC_AUDIT_GROUP
62908+ bool "Single group for auditing"
62909+ help
62910+ If you say Y here, the exec and chdir logging features will only operate
62911+ on a group you specify. This option is recommended if you only want to
62912+ watch certain users instead of having a large amount of logs from the
62913+ entire system. If the sysctl option is enabled, a sysctl option with
62914+ name "audit_group" is created.
62915+
62916+config GRKERNSEC_AUDIT_GID
62917+ int "GID for auditing"
62918+ depends on GRKERNSEC_AUDIT_GROUP
62919+ default 1007
62920+
62921+config GRKERNSEC_EXECLOG
62922+ bool "Exec logging"
62923+ help
62924+ If you say Y here, all execve() calls will be logged (since the
62925+ other exec*() calls are frontends to execve(), all execution
62926+ will be logged). Useful for shell-servers that like to keep track
62927+ of their users. If the sysctl option is enabled, a sysctl option with
62928+ name "exec_logging" is created.
62929+ WARNING: This option when enabled will produce a LOT of logs, especially
62930+ on an active system.
62931+
62932+config GRKERNSEC_RESLOG
62933+ bool "Resource logging"
62934+ default y if GRKERNSEC_CONFIG_AUTO
62935+ help
62936+ If you say Y here, all attempts to overstep resource limits will
62937+ be logged with the resource name, the requested size, and the current
62938+ limit. It is highly recommended that you say Y here. If the sysctl
62939+ option is enabled, a sysctl option with name "resource_logging" is
62940+ created. If the RBAC system is enabled, the sysctl value is ignored.
62941+
62942+config GRKERNSEC_CHROOT_EXECLOG
62943+ bool "Log execs within chroot"
62944+ help
62945+ If you say Y here, all executions inside a chroot jail will be logged
62946+ to syslog. This can cause a large amount of logs if certain
62947+ applications (eg. djb's daemontools) are installed on the system, and
62948+ is therefore left as an option. If the sysctl option is enabled, a
62949+ sysctl option with name "chroot_execlog" is created.
62950+
62951+config GRKERNSEC_AUDIT_PTRACE
62952+ bool "Ptrace logging"
62953+ help
62954+ If you say Y here, all attempts to attach to a process via ptrace
62955+ will be logged. If the sysctl option is enabled, a sysctl option
62956+ with name "audit_ptrace" is created.
62957+
62958+config GRKERNSEC_AUDIT_CHDIR
62959+ bool "Chdir logging"
62960+ help
62961+ If you say Y here, all chdir() calls will be logged. If the sysctl
62962+ option is enabled, a sysctl option with name "audit_chdir" is created.
62963+
62964+config GRKERNSEC_AUDIT_MOUNT
62965+ bool "(Un)Mount logging"
62966+ help
62967+ If you say Y here, all mounts and unmounts will be logged. If the
62968+ sysctl option is enabled, a sysctl option with name "audit_mount" is
62969+ created.
62970+
62971+config GRKERNSEC_SIGNAL
62972+ bool "Signal logging"
62973+ default y if GRKERNSEC_CONFIG_AUTO
62974+ help
62975+ If you say Y here, certain important signals will be logged, such as
62976+ SIGSEGV, which will as a result inform you of when a error in a program
62977+ occurred, which in some cases could mean a possible exploit attempt.
62978+ If the sysctl option is enabled, a sysctl option with name
62979+ "signal_logging" is created.
62980+
62981+config GRKERNSEC_FORKFAIL
62982+ bool "Fork failure logging"
62983+ help
62984+ If you say Y here, all failed fork() attempts will be logged.
62985+ This could suggest a fork bomb, or someone attempting to overstep
62986+ their process limit. If the sysctl option is enabled, a sysctl option
62987+ with name "forkfail_logging" is created.
62988+
62989+config GRKERNSEC_TIME
62990+ bool "Time change logging"
62991+ default y if GRKERNSEC_CONFIG_AUTO
62992+ help
62993+ If you say Y here, any changes of the system clock will be logged.
62994+ If the sysctl option is enabled, a sysctl option with name
62995+ "timechange_logging" is created.
62996+
62997+config GRKERNSEC_PROC_IPADDR
62998+ bool "/proc/<pid>/ipaddr support"
62999+ default y if GRKERNSEC_CONFIG_AUTO
63000+ help
63001+ If you say Y here, a new entry will be added to each /proc/<pid>
63002+ directory that contains the IP address of the person using the task.
63003+ The IP is carried across local TCP and AF_UNIX stream sockets.
63004+ This information can be useful for IDS/IPSes to perform remote response
63005+ to a local attack. The entry is readable by only the owner of the
63006+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
63007+ the RBAC system), and thus does not create privacy concerns.
63008+
63009+config GRKERNSEC_RWXMAP_LOG
63010+ bool 'Denied RWX mmap/mprotect logging'
63011+ default y if GRKERNSEC_CONFIG_AUTO
63012+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
63013+ help
63014+ If you say Y here, calls to mmap() and mprotect() with explicit
63015+ usage of PROT_WRITE and PROT_EXEC together will be logged when
63016+ denied by the PAX_MPROTECT feature. This feature will also
63017+ log other problematic scenarios that can occur when PAX_MPROTECT
63018+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
63019+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
63020+ is created.
63021+
63022+endmenu
63023+
63024+menu "Executable Protections"
63025+depends on GRKERNSEC
63026+
63027+config GRKERNSEC_DMESG
63028+ bool "Dmesg(8) restriction"
63029+ default y if GRKERNSEC_CONFIG_AUTO
63030+ help
63031+ If you say Y here, non-root users will not be able to use dmesg(8)
63032+ to view the contents of the kernel's circular log buffer.
63033+ The kernel's log buffer often contains kernel addresses and other
63034+ identifying information useful to an attacker in fingerprinting a
63035+ system for a targeted exploit.
63036+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
63037+ created.
63038+
63039+config GRKERNSEC_HARDEN_PTRACE
63040+ bool "Deter ptrace-based process snooping"
63041+ default y if GRKERNSEC_CONFIG_AUTO
63042+ help
63043+ If you say Y here, TTY sniffers and other malicious monitoring
63044+ programs implemented through ptrace will be defeated. If you
63045+ have been using the RBAC system, this option has already been
63046+ enabled for several years for all users, with the ability to make
63047+ fine-grained exceptions.
63048+
63049+ This option only affects the ability of non-root users to ptrace
63050+ processes that are not a descendent of the ptracing process.
63051+ This means that strace ./binary and gdb ./binary will still work,
63052+ but attaching to arbitrary processes will not. If the sysctl
63053+ option is enabled, a sysctl option with name "harden_ptrace" is
63054+ created.
63055+
63056+config GRKERNSEC_PTRACE_READEXEC
63057+ bool "Require read access to ptrace sensitive binaries"
63058+ default y if GRKERNSEC_CONFIG_AUTO
63059+ help
63060+ If you say Y here, unprivileged users will not be able to ptrace unreadable
63061+ binaries. This option is useful in environments that
63062+ remove the read bits (e.g. file mode 4711) from suid binaries to
63063+ prevent infoleaking of their contents. This option adds
63064+ consistency to the use of that file mode, as the binary could normally
63065+ be read out when run without privileges while ptracing.
63066+
63067+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
63068+ is created.
63069+
63070+config GRKERNSEC_SETXID
63071+ bool "Enforce consistent multithreaded privileges"
63072+ default y if GRKERNSEC_CONFIG_AUTO
63073+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
63074+ help
63075+ If you say Y here, a change from a root uid to a non-root uid
63076+ in a multithreaded application will cause the resulting uids,
63077+ gids, supplementary groups, and capabilities in that thread
63078+ to be propagated to the other threads of the process. In most
63079+ cases this is unnecessary, as glibc will emulate this behavior
63080+ on behalf of the application. Other libcs do not act in the
63081+ same way, allowing the other threads of the process to continue
63082+ running with root privileges. If the sysctl option is enabled,
63083+ a sysctl option with name "consistent_setxid" is created.
63084+
63085+config GRKERNSEC_TPE
63086+ bool "Trusted Path Execution (TPE)"
63087+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
63088+ help
63089+ If you say Y here, you will be able to choose a gid to add to the
63090+ supplementary groups of users you want to mark as "untrusted."
63091+ These users will not be able to execute any files that are not in
63092+ root-owned directories writable only by root. If the sysctl option
63093+ is enabled, a sysctl option with name "tpe" is created.
63094+
63095+config GRKERNSEC_TPE_ALL
63096+ bool "Partially restrict all non-root users"
63097+ depends on GRKERNSEC_TPE
63098+ help
63099+ If you say Y here, all non-root users will be covered under
63100+ a weaker TPE restriction. This is separate from, and in addition to,
63101+ the main TPE options that you have selected elsewhere. Thus, if a
63102+ "trusted" GID is chosen, this restriction applies to even that GID.
63103+ Under this restriction, all non-root users will only be allowed to
63104+ execute files in directories they own that are not group or
63105+ world-writable, or in directories owned by root and writable only by
63106+ root. If the sysctl option is enabled, a sysctl option with name
63107+ "tpe_restrict_all" is created.
63108+
63109+config GRKERNSEC_TPE_INVERT
63110+ bool "Invert GID option"
63111+ depends on GRKERNSEC_TPE
63112+ help
63113+ If you say Y here, the group you specify in the TPE configuration will
63114+ decide what group TPE restrictions will be *disabled* for. This
63115+ option is useful if you want TPE restrictions to be applied to most
63116+ users on the system. If the sysctl option is enabled, a sysctl option
63117+ with name "tpe_invert" is created. Unlike other sysctl options, this
63118+ entry will default to on for backward-compatibility.
63119+
63120+config GRKERNSEC_TPE_GID
63121+ int
63122+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
63123+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
63124+
63125+config GRKERNSEC_TPE_UNTRUSTED_GID
63126+ int "GID for TPE-untrusted users"
63127+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
63128+ default 1005
63129+ help
63130+ Setting this GID determines what group TPE restrictions will be
63131+ *enabled* for. If the sysctl option is enabled, a sysctl option
63132+ with name "tpe_gid" is created.
63133+
63134+config GRKERNSEC_TPE_TRUSTED_GID
63135+ int "GID for TPE-trusted users"
63136+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
63137+ default 1005
63138+ help
63139+ Setting this GID determines what group TPE restrictions will be
63140+ *disabled* for. If the sysctl option is enabled, a sysctl option
63141+ with name "tpe_gid" is created.
63142+
63143+endmenu
63144+menu "Network Protections"
63145+depends on GRKERNSEC
63146+
63147+config GRKERNSEC_RANDNET
63148+ bool "Larger entropy pools"
63149+ default y if GRKERNSEC_CONFIG_AUTO
63150+ help
63151+ If you say Y here, the entropy pools used for many features of Linux
63152+ and grsecurity will be doubled in size. Since several grsecurity
63153+ features use additional randomness, it is recommended that you say Y
63154+ here. Saying Y here has a similar effect as modifying
63155+ /proc/sys/kernel/random/poolsize.
63156+
63157+config GRKERNSEC_BLACKHOLE
63158+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
63159+ default y if GRKERNSEC_CONFIG_AUTO
63160+ depends on NET
63161+ help
63162+ If you say Y here, neither TCP resets nor ICMP
63163+ destination-unreachable packets will be sent in response to packets
63164+ sent to ports for which no associated listening process exists.
63165+ This feature supports both IPV4 and IPV6 and exempts the
63166+ loopback interface from blackholing. Enabling this feature
63167+ makes a host more resilient to DoS attacks and reduces network
63168+ visibility against scanners.
63169+
63170+ The blackhole feature as-implemented is equivalent to the FreeBSD
63171+ blackhole feature, as it prevents RST responses to all packets, not
63172+ just SYNs. Under most application behavior this causes no
63173+ problems, but applications (like haproxy) may not close certain
63174+ connections in a way that cleanly terminates them on the remote
63175+ end, leaving the remote host in LAST_ACK state. Because of this
63176+ side-effect and to prevent intentional LAST_ACK DoSes, this
63177+ feature also adds automatic mitigation against such attacks.
63178+ The mitigation drastically reduces the amount of time a socket
63179+ can spend in LAST_ACK state. If you're using haproxy and not
63180+ all servers it connects to have this option enabled, consider
63181+ disabling this feature on the haproxy host.
63182+
63183+ If the sysctl option is enabled, two sysctl options with names
63184+ "ip_blackhole" and "lastack_retries" will be created.
63185+ While "ip_blackhole" takes the standard zero/non-zero on/off
63186+ toggle, "lastack_retries" uses the same kinds of values as
63187+ "tcp_retries1" and "tcp_retries2". The default value of 4
63188+ prevents a socket from lasting more than 45 seconds in LAST_ACK
63189+ state.
63190+
63191+config GRKERNSEC_NO_SIMULT_CONNECT
63192+ bool "Disable TCP Simultaneous Connect"
63193+ default y if GRKERNSEC_CONFIG_AUTO
63194+ depends on NET
63195+ help
63196+ If you say Y here, a feature by Willy Tarreau will be enabled that
63197+ removes a weakness in Linux's strict implementation of TCP that
63198+ allows two clients to connect to each other without either entering
63199+ a listening state. The weakness allows an attacker to easily prevent
63200+ a client from connecting to a known server provided the source port
63201+ for the connection is guessed correctly.
63202+
63203+ As the weakness could be used to prevent an antivirus or IPS from
63204+ fetching updates, or prevent an SSL gateway from fetching a CRL,
63205+ it should be eliminated by enabling this option. Though Linux is
63206+ one of few operating systems supporting simultaneous connect, it
63207+ has no legitimate use in practice and is rarely supported by firewalls.
63208+
63209+config GRKERNSEC_SOCKET
63210+ bool "Socket restrictions"
63211+ depends on NET
63212+ help
63213+ If you say Y here, you will be able to choose from several options.
63214+ If you assign a GID on your system and add it to the supplementary
63215+ groups of users you want to restrict socket access to, this patch
63216+ will perform up to three things, based on the option(s) you choose.
63217+
63218+config GRKERNSEC_SOCKET_ALL
63219+ bool "Deny any sockets to group"
63220+ depends on GRKERNSEC_SOCKET
63221+ help
63222+ If you say Y here, you will be able to choose a GID of whose users will
63223+ be unable to connect to other hosts from your machine or run server
63224+ applications from your machine. If the sysctl option is enabled, a
63225+ sysctl option with name "socket_all" is created.
63226+
63227+config GRKERNSEC_SOCKET_ALL_GID
63228+ int "GID to deny all sockets for"
63229+ depends on GRKERNSEC_SOCKET_ALL
63230+ default 1004
63231+ help
63232+ Here you can choose the GID to disable socket access for. Remember to
63233+ add the users you want socket access disabled for to the GID
63234+ specified here. If the sysctl option is enabled, a sysctl option
63235+ with name "socket_all_gid" is created.
63236+
63237+config GRKERNSEC_SOCKET_CLIENT
63238+ bool "Deny client sockets to group"
63239+ depends on GRKERNSEC_SOCKET
63240+ help
63241+ If you say Y here, you will be able to choose a GID of whose users will
63242+ be unable to connect to other hosts from your machine, but will be
63243+ able to run servers. If this option is enabled, all users in the group
63244+ you specify will have to use passive mode when initiating ftp transfers
63245+ from the shell on your machine. If the sysctl option is enabled, a
63246+ sysctl option with name "socket_client" is created.
63247+
63248+config GRKERNSEC_SOCKET_CLIENT_GID
63249+ int "GID to deny client sockets for"
63250+ depends on GRKERNSEC_SOCKET_CLIENT
63251+ default 1003
63252+ help
63253+ Here you can choose the GID to disable client socket access for.
63254+ Remember to add the users you want client socket access disabled for to
63255+ the GID specified here. If the sysctl option is enabled, a sysctl
63256+ option with name "socket_client_gid" is created.
63257+
63258+config GRKERNSEC_SOCKET_SERVER
63259+ bool "Deny server sockets to group"
63260+ depends on GRKERNSEC_SOCKET
63261+ help
63262+ If you say Y here, you will be able to choose a GID of whose users will
63263+ be unable to run server applications from your machine. If the sysctl
63264+ option is enabled, a sysctl option with name "socket_server" is created.
63265+
63266+config GRKERNSEC_SOCKET_SERVER_GID
63267+ int "GID to deny server sockets for"
63268+ depends on GRKERNSEC_SOCKET_SERVER
63269+ default 1002
63270+ help
63271+ Here you can choose the GID to disable server socket access for.
63272+ Remember to add the users you want server socket access disabled for to
63273+ the GID specified here. If the sysctl option is enabled, a sysctl
63274+ option with name "socket_server_gid" is created.
63275+
63276+endmenu
63277+
63278+menu "Physical Protections"
63279+depends on GRKERNSEC
63280+
63281+config GRKERNSEC_DENYUSB
63282+ bool "Deny new USB connections after toggle"
63283+ default y if GRKERNSEC_CONFIG_AUTO
63284+ help
63285+ If you say Y here, a new sysctl option with name "deny_new_usb"
63286+ will be created. Setting its value to 1 will prevent any new
63287+ USB devices from being recognized by the OS. Any attempted USB
63288+ device insertion will be logged. This option is intended to be
63289+ used against custom USB devices designed to exploit vulnerabilities
63290+ in various USB device drivers.
63291+
63292+ For greatest effectiveness, this sysctl should be set after any
63293+ relevant init scripts. This option is safe to enable in distros
63294+ as each user can choose whether or not to toggle the sysctl.
63295+
63296+config GRKERNSEC_DENYUSB_FORCE
63297+ bool "Reject all USB devices not connected at boot"
63298+ select USB
63299+ depends on SYSCTL && GRKERNSEC_DENYUSB
63300+ help
63301+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
63302+ that doesn't involve a sysctl entry. This option should only be
63303+ enabled if you're sure you want to deny all new USB connections
63304+ at runtime and don't want to modify init scripts. This should not
63305+ be enabled by distros. It forces the core USB code to be built
63306+ into the kernel image so that all devices connected at boot time
63307+ can be recognized and new USB device connections can be prevented
63308+ prior to init running.
63309+
63310+endmenu
63311+
63312+menu "Sysctl Support"
63313+depends on GRKERNSEC && SYSCTL
63314+
63315+config GRKERNSEC_SYSCTL
63316+ bool "Sysctl support"
63317+ default y if GRKERNSEC_CONFIG_AUTO
63318+ help
63319+ If you say Y here, you will be able to change the options that
63320+ grsecurity runs with at bootup, without having to recompile your
63321+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
63322+ to enable (1) or disable (0) various features. All the sysctl entries
63323+ are mutable until the "grsec_lock" entry is set to a non-zero value.
63324+ All features enabled in the kernel configuration are disabled at boot
63325+ if you do not say Y to the "Turn on features by default" option.
63326+ All options should be set at startup, and the grsec_lock entry should
63327+ be set to a non-zero value after all the options are set.
63328+ *THIS IS EXTREMELY IMPORTANT*
63329+
63330+config GRKERNSEC_SYSCTL_DISTRO
63331+ bool "Extra sysctl support for distro makers (READ HELP)"
63332+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
63333+ help
63334+ If you say Y here, additional sysctl options will be created
63335+ for features that affect processes running as root. Therefore,
63336+ it is critical when using this option that the grsec_lock entry be
63337+ enabled after boot. Only distros with prebuilt kernel packages
63338+ with this option enabled that can ensure grsec_lock is enabled
63339+ after boot should use this option.
63340+ *Failure to set grsec_lock after boot makes all grsec features
63341+ this option covers useless*
63342+
63343+ Currently this option creates the following sysctl entries:
63344+ "Disable Privileged I/O": "disable_priv_io"
63345+
63346+config GRKERNSEC_SYSCTL_ON
63347+ bool "Turn on features by default"
63348+ default y if GRKERNSEC_CONFIG_AUTO
63349+ depends on GRKERNSEC_SYSCTL
63350+ help
63351+ If you say Y here, instead of having all features enabled in the
63352+ kernel configuration disabled at boot time, the features will be
63353+ enabled at boot time. It is recommended you say Y here unless
63354+ there is some reason you would want all sysctl-tunable features to
63355+ be disabled by default. As mentioned elsewhere, it is important
63356+ to enable the grsec_lock entry once you have finished modifying
63357+ the sysctl entries.
63358+
63359+endmenu
63360+menu "Logging Options"
63361+depends on GRKERNSEC
63362+
63363+config GRKERNSEC_FLOODTIME
63364+ int "Seconds in between log messages (minimum)"
63365+ default 10
63366+ help
63367+ This option allows you to enforce the number of seconds between
63368+ grsecurity log messages. The default should be suitable for most
63369+ people, however, if you choose to change it, choose a value small enough
63370+ to allow informative logs to be produced, but large enough to
63371+ prevent flooding.
63372+
63373+config GRKERNSEC_FLOODBURST
63374+ int "Number of messages in a burst (maximum)"
63375+ default 6
63376+ help
63377+ This option allows you to choose the maximum number of messages allowed
63378+ within the flood time interval you chose in a separate option. The
63379+ default should be suitable for most people, however if you find that
63380+ many of your logs are being interpreted as flooding, you may want to
63381+ raise this value.
63382+
63383+endmenu
63384diff --git a/grsecurity/Makefile b/grsecurity/Makefile
63385new file mode 100644
63386index 0000000..b0b77d5
63387--- /dev/null
63388+++ b/grsecurity/Makefile
63389@@ -0,0 +1,43 @@
63390+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
63391+# during 2001-2009 it has been completely redesigned by Brad Spengler
63392+# into an RBAC system
63393+#
63394+# All code in this directory and various hooks inserted throughout the kernel
63395+# are copyright Brad Spengler - Open Source Security, Inc., and released
63396+# under the GPL v2 or higher
63397+
63398+KBUILD_CFLAGS += -Werror
63399+
63400+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
63401+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
63402+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
63403+ grsec_usb.o
63404+
63405+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
63406+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
63407+ gracl_learn.o grsec_log.o
63408+ifdef CONFIG_COMPAT
63409+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
63410+endif
63411+
63412+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
63413+
63414+ifdef CONFIG_NET
63415+obj-y += grsec_sock.o
63416+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
63417+endif
63418+
63419+ifndef CONFIG_GRKERNSEC
63420+obj-y += grsec_disabled.o
63421+endif
63422+
63423+ifdef CONFIG_GRKERNSEC_HIDESYM
63424+extra-y := grsec_hidesym.o
63425+$(obj)/grsec_hidesym.o:
63426+ @-chmod -f 500 /boot
63427+ @-chmod -f 500 /lib/modules
63428+ @-chmod -f 500 /lib64/modules
63429+ @-chmod -f 500 /lib32/modules
63430+ @-chmod -f 700 .
63431+ @echo ' grsec: protected kernel image paths'
63432+endif
63433diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
63434new file mode 100644
63435index 0000000..c0793fd
63436--- /dev/null
63437+++ b/grsecurity/gracl.c
63438@@ -0,0 +1,4178 @@
63439+#include <linux/kernel.h>
63440+#include <linux/module.h>
63441+#include <linux/sched.h>
63442+#include <linux/mm.h>
63443+#include <linux/file.h>
63444+#include <linux/fs.h>
63445+#include <linux/namei.h>
63446+#include <linux/mount.h>
63447+#include <linux/tty.h>
63448+#include <linux/proc_fs.h>
63449+#include <linux/lglock.h>
63450+#include <linux/slab.h>
63451+#include <linux/vmalloc.h>
63452+#include <linux/types.h>
63453+#include <linux/sysctl.h>
63454+#include <linux/netdevice.h>
63455+#include <linux/ptrace.h>
63456+#include <linux/gracl.h>
63457+#include <linux/gralloc.h>
63458+#include <linux/security.h>
63459+#include <linux/grinternal.h>
63460+#include <linux/pid_namespace.h>
63461+#include <linux/stop_machine.h>
63462+#include <linux/fdtable.h>
63463+#include <linux/percpu.h>
63464+#include <linux/lglock.h>
63465+#include <linux/hugetlb.h>
63466+#include <linux/posix-timers.h>
63467+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63468+#include <linux/magic.h>
63469+#include <linux/pagemap.h>
63470+#include "../fs/btrfs/async-thread.h"
63471+#include "../fs/btrfs/ctree.h"
63472+#include "../fs/btrfs/btrfs_inode.h"
63473+#endif
63474+#include "../fs/mount.h"
63475+
63476+#include <asm/uaccess.h>
63477+#include <asm/errno.h>
63478+#include <asm/mman.h>
63479+
63480+extern struct lglock vfsmount_lock;
63481+
63482+static struct acl_role_db acl_role_set;
63483+static struct name_db name_set;
63484+static struct inodev_db inodev_set;
63485+
63486+/* for keeping track of userspace pointers used for subjects, so we
63487+ can share references in the kernel as well
63488+*/
63489+
63490+static struct path real_root;
63491+
63492+static struct acl_subj_map_db subj_map_set;
63493+
63494+static struct acl_role_label *default_role;
63495+
63496+static struct acl_role_label *role_list;
63497+
63498+static u16 acl_sp_role_value;
63499+
63500+extern char *gr_shared_page[4];
63501+static DEFINE_MUTEX(gr_dev_mutex);
63502+DEFINE_RWLOCK(gr_inode_lock);
63503+
63504+struct gr_arg *gr_usermode;
63505+
63506+static unsigned int gr_status __read_only = GR_STATUS_INIT;
63507+
63508+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
63509+extern void gr_clear_learn_entries(void);
63510+
63511+unsigned char *gr_system_salt;
63512+unsigned char *gr_system_sum;
63513+
63514+static struct sprole_pw **acl_special_roles = NULL;
63515+static __u16 num_sprole_pws = 0;
63516+
63517+static struct acl_role_label *kernel_role = NULL;
63518+
63519+static unsigned int gr_auth_attempts = 0;
63520+static unsigned long gr_auth_expires = 0UL;
63521+
63522+#ifdef CONFIG_NET
63523+extern struct vfsmount *sock_mnt;
63524+#endif
63525+
63526+extern struct vfsmount *pipe_mnt;
63527+extern struct vfsmount *shm_mnt;
63528+
63529+#ifdef CONFIG_HUGETLBFS
63530+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63531+#endif
63532+
63533+static struct acl_object_label *fakefs_obj_rw;
63534+static struct acl_object_label *fakefs_obj_rwx;
63535+
63536+extern int gr_init_uidset(void);
63537+extern void gr_free_uidset(void);
63538+extern void gr_remove_uid(uid_t uid);
63539+extern int gr_find_uid(uid_t uid);
63540+
63541+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
63542+{
63543+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
63544+ return -EFAULT;
63545+
63546+ return 0;
63547+}
63548+
63549+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
63550+{
63551+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
63552+ return -EFAULT;
63553+
63554+ return 0;
63555+}
63556+
63557+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
63558+{
63559+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
63560+ return -EFAULT;
63561+
63562+ return 0;
63563+}
63564+
63565+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
63566+{
63567+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
63568+ return -EFAULT;
63569+
63570+ return 0;
63571+}
63572+
63573+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
63574+{
63575+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
63576+ return -EFAULT;
63577+
63578+ return 0;
63579+}
63580+
63581+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
63582+{
63583+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
63584+ return -EFAULT;
63585+
63586+ return 0;
63587+}
63588+
63589+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
63590+{
63591+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
63592+ return -EFAULT;
63593+
63594+ return 0;
63595+}
63596+
63597+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
63598+{
63599+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
63600+ return -EFAULT;
63601+
63602+ return 0;
63603+}
63604+
63605+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
63606+{
63607+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
63608+ return -EFAULT;
63609+
63610+ return 0;
63611+}
63612+
63613+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
63614+{
63615+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
63616+ return -EFAULT;
63617+
63618+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
63619+ return -EINVAL;
63620+
63621+ return 0;
63622+}
63623+
63624+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
63625+{
63626+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
63627+ return -EFAULT;
63628+
63629+ return 0;
63630+}
63631+
63632+static size_t get_gr_arg_wrapper_size_normal(void)
63633+{
63634+ return sizeof(struct gr_arg_wrapper);
63635+}
63636+
63637+#ifdef CONFIG_COMPAT
63638+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
63639+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
63640+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
63641+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
63642+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
63643+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
63644+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
63645+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
63646+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
63647+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
63648+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
63649+extern size_t get_gr_arg_wrapper_size_compat(void);
63650+
63651+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
63652+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
63653+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
63654+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
63655+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
63656+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
63657+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
63658+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
63659+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
63660+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
63661+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
63662+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
63663+
63664+#else
63665+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
63666+#define copy_gr_arg copy_gr_arg_normal
63667+#define copy_gr_hash_struct copy_gr_hash_struct_normal
63668+#define copy_acl_object_label copy_acl_object_label_normal
63669+#define copy_acl_subject_label copy_acl_subject_label_normal
63670+#define copy_acl_role_label copy_acl_role_label_normal
63671+#define copy_acl_ip_label copy_acl_ip_label_normal
63672+#define copy_pointer_from_array copy_pointer_from_array_normal
63673+#define copy_sprole_pw copy_sprole_pw_normal
63674+#define copy_role_transition copy_role_transition_normal
63675+#define copy_role_allowed_ip copy_role_allowed_ip_normal
63676+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
63677+#endif
63678+
63679+__inline__ int
63680+gr_acl_is_enabled(void)
63681+{
63682+ return (gr_status & GR_READY);
63683+}
63684+
63685+static inline dev_t __get_dev(const struct dentry *dentry)
63686+{
63687+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63688+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63689+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63690+ else
63691+#endif
63692+ return dentry->d_sb->s_dev;
63693+}
63694+
63695+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63696+{
63697+ return __get_dev(dentry);
63698+}
63699+
63700+static char gr_task_roletype_to_char(struct task_struct *task)
63701+{
63702+ switch (task->role->roletype &
63703+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
63704+ GR_ROLE_SPECIAL)) {
63705+ case GR_ROLE_DEFAULT:
63706+ return 'D';
63707+ case GR_ROLE_USER:
63708+ return 'U';
63709+ case GR_ROLE_GROUP:
63710+ return 'G';
63711+ case GR_ROLE_SPECIAL:
63712+ return 'S';
63713+ }
63714+
63715+ return 'X';
63716+}
63717+
63718+char gr_roletype_to_char(void)
63719+{
63720+ return gr_task_roletype_to_char(current);
63721+}
63722+
63723+__inline__ int
63724+gr_acl_tpe_check(void)
63725+{
63726+ if (unlikely(!(gr_status & GR_READY)))
63727+ return 0;
63728+ if (current->role->roletype & GR_ROLE_TPE)
63729+ return 1;
63730+ else
63731+ return 0;
63732+}
63733+
63734+int
63735+gr_handle_rawio(const struct inode *inode)
63736+{
63737+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63738+ if (inode && S_ISBLK(inode->i_mode) &&
63739+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
63740+ !capable(CAP_SYS_RAWIO))
63741+ return 1;
63742+#endif
63743+ return 0;
63744+}
63745+
63746+static int
63747+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
63748+{
63749+ if (likely(lena != lenb))
63750+ return 0;
63751+
63752+ return !memcmp(a, b, lena);
63753+}
63754+
63755+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
63756+{
63757+ *buflen -= namelen;
63758+ if (*buflen < 0)
63759+ return -ENAMETOOLONG;
63760+ *buffer -= namelen;
63761+ memcpy(*buffer, str, namelen);
63762+ return 0;
63763+}
63764+
63765+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
63766+{
63767+ return prepend(buffer, buflen, name->name, name->len);
63768+}
63769+
63770+static int prepend_path(const struct path *path, struct path *root,
63771+ char **buffer, int *buflen)
63772+{
63773+ struct dentry *dentry = path->dentry;
63774+ struct vfsmount *vfsmnt = path->mnt;
63775+ struct mount *mnt = real_mount(vfsmnt);
63776+ bool slash = false;
63777+ int error = 0;
63778+
63779+ while (dentry != root->dentry || vfsmnt != root->mnt) {
63780+ struct dentry * parent;
63781+
63782+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
63783+ /* Global root? */
63784+ if (!mnt_has_parent(mnt)) {
63785+ goto out;
63786+ }
63787+ dentry = mnt->mnt_mountpoint;
63788+ mnt = mnt->mnt_parent;
63789+ vfsmnt = &mnt->mnt;
63790+ continue;
63791+ }
63792+ parent = dentry->d_parent;
63793+ prefetch(parent);
63794+ spin_lock(&dentry->d_lock);
63795+ error = prepend_name(buffer, buflen, &dentry->d_name);
63796+ spin_unlock(&dentry->d_lock);
63797+ if (!error)
63798+ error = prepend(buffer, buflen, "/", 1);
63799+ if (error)
63800+ break;
63801+
63802+ slash = true;
63803+ dentry = parent;
63804+ }
63805+
63806+out:
63807+ if (!error && !slash)
63808+ error = prepend(buffer, buflen, "/", 1);
63809+
63810+ return error;
63811+}
63812+
63813+/* this must be called with vfsmount_lock and rename_lock held */
63814+
63815+static char *__our_d_path(const struct path *path, struct path *root,
63816+ char *buf, int buflen)
63817+{
63818+ char *res = buf + buflen;
63819+ int error;
63820+
63821+ prepend(&res, &buflen, "\0", 1);
63822+ error = prepend_path(path, root, &res, &buflen);
63823+ if (error)
63824+ return ERR_PTR(error);
63825+
63826+ return res;
63827+}
63828+
63829+static char *
63830+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
63831+{
63832+ char *retval;
63833+
63834+ retval = __our_d_path(path, root, buf, buflen);
63835+ if (unlikely(IS_ERR(retval)))
63836+ retval = strcpy(buf, "<path too long>");
63837+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
63838+ retval[1] = '\0';
63839+
63840+ return retval;
63841+}
63842+
63843+static char *
63844+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63845+ char *buf, int buflen)
63846+{
63847+ struct path path;
63848+ char *res;
63849+
63850+ path.dentry = (struct dentry *)dentry;
63851+ path.mnt = (struct vfsmount *)vfsmnt;
63852+
63853+ /* we can use real_root.dentry, real_root.mnt, because this is only called
63854+ by the RBAC system */
63855+ res = gen_full_path(&path, &real_root, buf, buflen);
63856+
63857+ return res;
63858+}
63859+
63860+static char *
63861+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63862+ char *buf, int buflen)
63863+{
63864+ char *res;
63865+ struct path path;
63866+ struct path root;
63867+ struct task_struct *reaper = init_pid_ns.child_reaper;
63868+
63869+ path.dentry = (struct dentry *)dentry;
63870+ path.mnt = (struct vfsmount *)vfsmnt;
63871+
63872+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
63873+ get_fs_root(reaper->fs, &root);
63874+
63875+ br_read_lock(&vfsmount_lock);
63876+ write_seqlock(&rename_lock);
63877+ res = gen_full_path(&path, &root, buf, buflen);
63878+ write_sequnlock(&rename_lock);
63879+ br_read_unlock(&vfsmount_lock);
63880+
63881+ path_put(&root);
63882+ return res;
63883+}
63884+
63885+static char *
63886+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63887+{
63888+ char *ret;
63889+ br_read_lock(&vfsmount_lock);
63890+ write_seqlock(&rename_lock);
63891+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63892+ PAGE_SIZE);
63893+ write_sequnlock(&rename_lock);
63894+ br_read_unlock(&vfsmount_lock);
63895+ return ret;
63896+}
63897+
63898+static char *
63899+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63900+{
63901+ char *ret;
63902+ char *buf;
63903+ int buflen;
63904+
63905+ br_read_lock(&vfsmount_lock);
63906+ write_seqlock(&rename_lock);
63907+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
63908+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
63909+ buflen = (int)(ret - buf);
63910+ if (buflen >= 5)
63911+ prepend(&ret, &buflen, "/proc", 5);
63912+ else
63913+ ret = strcpy(buf, "<path too long>");
63914+ write_sequnlock(&rename_lock);
63915+ br_read_unlock(&vfsmount_lock);
63916+ return ret;
63917+}
63918+
63919+char *
63920+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
63921+{
63922+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63923+ PAGE_SIZE);
63924+}
63925+
63926+char *
63927+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
63928+{
63929+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
63930+ PAGE_SIZE);
63931+}
63932+
63933+char *
63934+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
63935+{
63936+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
63937+ PAGE_SIZE);
63938+}
63939+
63940+char *
63941+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
63942+{
63943+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
63944+ PAGE_SIZE);
63945+}
63946+
63947+char *
63948+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
63949+{
63950+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
63951+ PAGE_SIZE);
63952+}
63953+
63954+__inline__ __u32
63955+to_gr_audit(const __u32 reqmode)
63956+{
63957+ /* masks off auditable permission flags, then shifts them to create
63958+ auditing flags, and adds the special case of append auditing if
63959+ we're requesting write */
63960+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
63961+}
63962+
63963+struct acl_subject_label *
63964+lookup_subject_map(const struct acl_subject_label *userp)
63965+{
63966+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
63967+ struct subject_map *match;
63968+
63969+ match = subj_map_set.s_hash[index];
63970+
63971+ while (match && match->user != userp)
63972+ match = match->next;
63973+
63974+ if (match != NULL)
63975+ return match->kernel;
63976+ else
63977+ return NULL;
63978+}
63979+
63980+static void
63981+insert_subj_map_entry(struct subject_map *subjmap)
63982+{
63983+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
63984+ struct subject_map **curr;
63985+
63986+ subjmap->prev = NULL;
63987+
63988+ curr = &subj_map_set.s_hash[index];
63989+ if (*curr != NULL)
63990+ (*curr)->prev = subjmap;
63991+
63992+ subjmap->next = *curr;
63993+ *curr = subjmap;
63994+
63995+ return;
63996+}
63997+
63998+static struct acl_role_label *
63999+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
64000+ const gid_t gid)
64001+{
64002+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
64003+ struct acl_role_label *match;
64004+ struct role_allowed_ip *ipp;
64005+ unsigned int x;
64006+ u32 curr_ip = task->signal->curr_ip;
64007+
64008+ task->signal->saved_ip = curr_ip;
64009+
64010+ match = acl_role_set.r_hash[index];
64011+
64012+ while (match) {
64013+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
64014+ for (x = 0; x < match->domain_child_num; x++) {
64015+ if (match->domain_children[x] == uid)
64016+ goto found;
64017+ }
64018+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
64019+ break;
64020+ match = match->next;
64021+ }
64022+found:
64023+ if (match == NULL) {
64024+ try_group:
64025+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
64026+ match = acl_role_set.r_hash[index];
64027+
64028+ while (match) {
64029+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
64030+ for (x = 0; x < match->domain_child_num; x++) {
64031+ if (match->domain_children[x] == gid)
64032+ goto found2;
64033+ }
64034+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
64035+ break;
64036+ match = match->next;
64037+ }
64038+found2:
64039+ if (match == NULL)
64040+ match = default_role;
64041+ if (match->allowed_ips == NULL)
64042+ return match;
64043+ else {
64044+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64045+ if (likely
64046+ ((ntohl(curr_ip) & ipp->netmask) ==
64047+ (ntohl(ipp->addr) & ipp->netmask)))
64048+ return match;
64049+ }
64050+ match = default_role;
64051+ }
64052+ } else if (match->allowed_ips == NULL) {
64053+ return match;
64054+ } else {
64055+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
64056+ if (likely
64057+ ((ntohl(curr_ip) & ipp->netmask) ==
64058+ (ntohl(ipp->addr) & ipp->netmask)))
64059+ return match;
64060+ }
64061+ goto try_group;
64062+ }
64063+
64064+ return match;
64065+}
64066+
64067+struct acl_subject_label *
64068+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
64069+ const struct acl_role_label *role)
64070+{
64071+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64072+ struct acl_subject_label *match;
64073+
64074+ match = role->subj_hash[index];
64075+
64076+ while (match && (match->inode != ino || match->device != dev ||
64077+ (match->mode & GR_DELETED))) {
64078+ match = match->next;
64079+ }
64080+
64081+ if (match && !(match->mode & GR_DELETED))
64082+ return match;
64083+ else
64084+ return NULL;
64085+}
64086+
64087+struct acl_subject_label *
64088+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
64089+ const struct acl_role_label *role)
64090+{
64091+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
64092+ struct acl_subject_label *match;
64093+
64094+ match = role->subj_hash[index];
64095+
64096+ while (match && (match->inode != ino || match->device != dev ||
64097+ !(match->mode & GR_DELETED))) {
64098+ match = match->next;
64099+ }
64100+
64101+ if (match && (match->mode & GR_DELETED))
64102+ return match;
64103+ else
64104+ return NULL;
64105+}
64106+
64107+static struct acl_object_label *
64108+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
64109+ const struct acl_subject_label *subj)
64110+{
64111+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64112+ struct acl_object_label *match;
64113+
64114+ match = subj->obj_hash[index];
64115+
64116+ while (match && (match->inode != ino || match->device != dev ||
64117+ (match->mode & GR_DELETED))) {
64118+ match = match->next;
64119+ }
64120+
64121+ if (match && !(match->mode & GR_DELETED))
64122+ return match;
64123+ else
64124+ return NULL;
64125+}
64126+
64127+static struct acl_object_label *
64128+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
64129+ const struct acl_subject_label *subj)
64130+{
64131+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
64132+ struct acl_object_label *match;
64133+
64134+ match = subj->obj_hash[index];
64135+
64136+ while (match && (match->inode != ino || match->device != dev ||
64137+ !(match->mode & GR_DELETED))) {
64138+ match = match->next;
64139+ }
64140+
64141+ if (match && (match->mode & GR_DELETED))
64142+ return match;
64143+
64144+ match = subj->obj_hash[index];
64145+
64146+ while (match && (match->inode != ino || match->device != dev ||
64147+ (match->mode & GR_DELETED))) {
64148+ match = match->next;
64149+ }
64150+
64151+ if (match && !(match->mode & GR_DELETED))
64152+ return match;
64153+ else
64154+ return NULL;
64155+}
64156+
64157+static struct name_entry *
64158+lookup_name_entry(const char *name)
64159+{
64160+ unsigned int len = strlen(name);
64161+ unsigned int key = full_name_hash(name, len);
64162+ unsigned int index = key % name_set.n_size;
64163+ struct name_entry *match;
64164+
64165+ match = name_set.n_hash[index];
64166+
64167+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
64168+ match = match->next;
64169+
64170+ return match;
64171+}
64172+
64173+static struct name_entry *
64174+lookup_name_entry_create(const char *name)
64175+{
64176+ unsigned int len = strlen(name);
64177+ unsigned int key = full_name_hash(name, len);
64178+ unsigned int index = key % name_set.n_size;
64179+ struct name_entry *match;
64180+
64181+ match = name_set.n_hash[index];
64182+
64183+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64184+ !match->deleted))
64185+ match = match->next;
64186+
64187+ if (match && match->deleted)
64188+ return match;
64189+
64190+ match = name_set.n_hash[index];
64191+
64192+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
64193+ match->deleted))
64194+ match = match->next;
64195+
64196+ if (match && !match->deleted)
64197+ return match;
64198+ else
64199+ return NULL;
64200+}
64201+
64202+static struct inodev_entry *
64203+lookup_inodev_entry(const ino_t ino, const dev_t dev)
64204+{
64205+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
64206+ struct inodev_entry *match;
64207+
64208+ match = inodev_set.i_hash[index];
64209+
64210+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
64211+ match = match->next;
64212+
64213+ return match;
64214+}
64215+
64216+static void
64217+insert_inodev_entry(struct inodev_entry *entry)
64218+{
64219+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
64220+ inodev_set.i_size);
64221+ struct inodev_entry **curr;
64222+
64223+ entry->prev = NULL;
64224+
64225+ curr = &inodev_set.i_hash[index];
64226+ if (*curr != NULL)
64227+ (*curr)->prev = entry;
64228+
64229+ entry->next = *curr;
64230+ *curr = entry;
64231+
64232+ return;
64233+}
64234+
64235+static void
64236+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
64237+{
64238+ unsigned int index =
64239+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
64240+ struct acl_role_label **curr;
64241+ struct acl_role_label *tmp, *tmp2;
64242+
64243+ curr = &acl_role_set.r_hash[index];
64244+
64245+ /* simple case, slot is empty, just set it to our role */
64246+ if (*curr == NULL) {
64247+ *curr = role;
64248+ } else {
64249+ /* example:
64250+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
64251+ 2 -> 3
64252+ */
64253+ /* first check to see if we can already be reached via this slot */
64254+ tmp = *curr;
64255+ while (tmp && tmp != role)
64256+ tmp = tmp->next;
64257+ if (tmp == role) {
64258+ /* we don't need to add ourselves to this slot's chain */
64259+ return;
64260+ }
64261+ /* we need to add ourselves to this chain, two cases */
64262+ if (role->next == NULL) {
64263+ /* simple case, append the current chain to our role */
64264+ role->next = *curr;
64265+ *curr = role;
64266+ } else {
64267+ /* 1 -> 2 -> 3 -> 4
64268+ 2 -> 3 -> 4
64269+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
64270+ */
64271+ /* trickier case: walk our role's chain until we find
64272+ the role for the start of the current slot's chain */
64273+ tmp = role;
64274+ tmp2 = *curr;
64275+ while (tmp->next && tmp->next != tmp2)
64276+ tmp = tmp->next;
64277+ if (tmp->next == tmp2) {
64278+ /* from example above, we found 3, so just
64279+ replace this slot's chain with ours */
64280+ *curr = role;
64281+ } else {
64282+ /* we didn't find a subset of our role's chain
64283+ in the current slot's chain, so append their
64284+ chain to ours, and set us as the first role in
64285+ the slot's chain
64286+
64287+ we could fold this case with the case above,
64288+ but making it explicit for clarity
64289+ */
64290+ tmp->next = tmp2;
64291+ *curr = role;
64292+ }
64293+ }
64294+ }
64295+
64296+ return;
64297+}
64298+
64299+static void
64300+insert_acl_role_label(struct acl_role_label *role)
64301+{
64302+ int i;
64303+
64304+ if (role_list == NULL) {
64305+ role_list = role;
64306+ role->prev = NULL;
64307+ } else {
64308+ role->prev = role_list;
64309+ role_list = role;
64310+ }
64311+
64312+ /* used for hash chains */
64313+ role->next = NULL;
64314+
64315+ if (role->roletype & GR_ROLE_DOMAIN) {
64316+ for (i = 0; i < role->domain_child_num; i++)
64317+ __insert_acl_role_label(role, role->domain_children[i]);
64318+ } else
64319+ __insert_acl_role_label(role, role->uidgid);
64320+}
64321+
64322+static int
64323+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
64324+{
64325+ struct name_entry **curr, *nentry;
64326+ struct inodev_entry *ientry;
64327+ unsigned int len = strlen(name);
64328+ unsigned int key = full_name_hash(name, len);
64329+ unsigned int index = key % name_set.n_size;
64330+
64331+ curr = &name_set.n_hash[index];
64332+
64333+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
64334+ curr = &((*curr)->next);
64335+
64336+ if (*curr != NULL)
64337+ return 1;
64338+
64339+ nentry = acl_alloc(sizeof (struct name_entry));
64340+ if (nentry == NULL)
64341+ return 0;
64342+ ientry = acl_alloc(sizeof (struct inodev_entry));
64343+ if (ientry == NULL)
64344+ return 0;
64345+ ientry->nentry = nentry;
64346+
64347+ nentry->key = key;
64348+ nentry->name = name;
64349+ nentry->inode = inode;
64350+ nentry->device = device;
64351+ nentry->len = len;
64352+ nentry->deleted = deleted;
64353+
64354+ nentry->prev = NULL;
64355+ curr = &name_set.n_hash[index];
64356+ if (*curr != NULL)
64357+ (*curr)->prev = nentry;
64358+ nentry->next = *curr;
64359+ *curr = nentry;
64360+
64361+ /* insert us into the table searchable by inode/dev */
64362+ insert_inodev_entry(ientry);
64363+
64364+ return 1;
64365+}
64366+
64367+static void
64368+insert_acl_obj_label(struct acl_object_label *obj,
64369+ struct acl_subject_label *subj)
64370+{
64371+ unsigned int index =
64372+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
64373+ struct acl_object_label **curr;
64374+
64375+
64376+ obj->prev = NULL;
64377+
64378+ curr = &subj->obj_hash[index];
64379+ if (*curr != NULL)
64380+ (*curr)->prev = obj;
64381+
64382+ obj->next = *curr;
64383+ *curr = obj;
64384+
64385+ return;
64386+}
64387+
64388+static void
64389+insert_acl_subj_label(struct acl_subject_label *obj,
64390+ struct acl_role_label *role)
64391+{
64392+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
64393+ struct acl_subject_label **curr;
64394+
64395+ obj->prev = NULL;
64396+
64397+ curr = &role->subj_hash[index];
64398+ if (*curr != NULL)
64399+ (*curr)->prev = obj;
64400+
64401+ obj->next = *curr;
64402+ *curr = obj;
64403+
64404+ return;
64405+}
64406+
64407+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
64408+
64409+static void *
64410+create_table(__u32 * len, int elementsize)
64411+{
64412+ unsigned int table_sizes[] = {
64413+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
64414+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
64415+ 4194301, 8388593, 16777213, 33554393, 67108859
64416+ };
64417+ void *newtable = NULL;
64418+ unsigned int pwr = 0;
64419+
64420+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
64421+ table_sizes[pwr] <= *len)
64422+ pwr++;
64423+
64424+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
64425+ return newtable;
64426+
64427+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
64428+ newtable =
64429+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
64430+ else
64431+ newtable = vmalloc(table_sizes[pwr] * elementsize);
64432+
64433+ *len = table_sizes[pwr];
64434+
64435+ return newtable;
64436+}
64437+
64438+static int
64439+init_variables(const struct gr_arg *arg)
64440+{
64441+ struct task_struct *reaper = init_pid_ns.child_reaper;
64442+ unsigned int stacksize;
64443+
64444+ subj_map_set.s_size = arg->role_db.num_subjects;
64445+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
64446+ name_set.n_size = arg->role_db.num_objects;
64447+ inodev_set.i_size = arg->role_db.num_objects;
64448+
64449+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
64450+ !name_set.n_size || !inodev_set.i_size)
64451+ return 1;
64452+
64453+ if (!gr_init_uidset())
64454+ return 1;
64455+
64456+ /* set up the stack that holds allocation info */
64457+
64458+ stacksize = arg->role_db.num_pointers + 5;
64459+
64460+ if (!acl_alloc_stack_init(stacksize))
64461+ return 1;
64462+
64463+ /* grab reference for the real root dentry and vfsmount */
64464+ get_fs_root(reaper->fs, &real_root);
64465+
64466+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64467+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
64468+#endif
64469+
64470+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
64471+ if (fakefs_obj_rw == NULL)
64472+ return 1;
64473+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
64474+
64475+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
64476+ if (fakefs_obj_rwx == NULL)
64477+ return 1;
64478+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
64479+
64480+ subj_map_set.s_hash =
64481+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
64482+ acl_role_set.r_hash =
64483+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
64484+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
64485+ inodev_set.i_hash =
64486+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
64487+
64488+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
64489+ !name_set.n_hash || !inodev_set.i_hash)
64490+ return 1;
64491+
64492+ memset(subj_map_set.s_hash, 0,
64493+ sizeof(struct subject_map *) * subj_map_set.s_size);
64494+ memset(acl_role_set.r_hash, 0,
64495+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
64496+ memset(name_set.n_hash, 0,
64497+ sizeof (struct name_entry *) * name_set.n_size);
64498+ memset(inodev_set.i_hash, 0,
64499+ sizeof (struct inodev_entry *) * inodev_set.i_size);
64500+
64501+ return 0;
64502+}
64503+
64504+/* free information not needed after startup
64505+ currently contains user->kernel pointer mappings for subjects
64506+*/
64507+
64508+static void
64509+free_init_variables(void)
64510+{
64511+ __u32 i;
64512+
64513+ if (subj_map_set.s_hash) {
64514+ for (i = 0; i < subj_map_set.s_size; i++) {
64515+ if (subj_map_set.s_hash[i]) {
64516+ kfree(subj_map_set.s_hash[i]);
64517+ subj_map_set.s_hash[i] = NULL;
64518+ }
64519+ }
64520+
64521+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
64522+ PAGE_SIZE)
64523+ kfree(subj_map_set.s_hash);
64524+ else
64525+ vfree(subj_map_set.s_hash);
64526+ }
64527+
64528+ return;
64529+}
64530+
64531+static void
64532+free_variables(void)
64533+{
64534+ struct acl_subject_label *s;
64535+ struct acl_role_label *r;
64536+ struct task_struct *task, *task2;
64537+ unsigned int x;
64538+
64539+ gr_clear_learn_entries();
64540+
64541+ read_lock(&tasklist_lock);
64542+ do_each_thread(task2, task) {
64543+ task->acl_sp_role = 0;
64544+ task->acl_role_id = 0;
64545+ task->acl = NULL;
64546+ task->role = NULL;
64547+ } while_each_thread(task2, task);
64548+ read_unlock(&tasklist_lock);
64549+
64550+ /* release the reference to the real root dentry and vfsmount */
64551+ path_put(&real_root);
64552+ memset(&real_root, 0, sizeof(real_root));
64553+
64554+ /* free all object hash tables */
64555+
64556+ FOR_EACH_ROLE_START(r)
64557+ if (r->subj_hash == NULL)
64558+ goto next_role;
64559+ FOR_EACH_SUBJECT_START(r, s, x)
64560+ if (s->obj_hash == NULL)
64561+ break;
64562+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
64563+ kfree(s->obj_hash);
64564+ else
64565+ vfree(s->obj_hash);
64566+ FOR_EACH_SUBJECT_END(s, x)
64567+ FOR_EACH_NESTED_SUBJECT_START(r, s)
64568+ if (s->obj_hash == NULL)
64569+ break;
64570+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
64571+ kfree(s->obj_hash);
64572+ else
64573+ vfree(s->obj_hash);
64574+ FOR_EACH_NESTED_SUBJECT_END(s)
64575+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
64576+ kfree(r->subj_hash);
64577+ else
64578+ vfree(r->subj_hash);
64579+ r->subj_hash = NULL;
64580+next_role:
64581+ FOR_EACH_ROLE_END(r)
64582+
64583+ acl_free_all();
64584+
64585+ if (acl_role_set.r_hash) {
64586+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
64587+ PAGE_SIZE)
64588+ kfree(acl_role_set.r_hash);
64589+ else
64590+ vfree(acl_role_set.r_hash);
64591+ }
64592+ if (name_set.n_hash) {
64593+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
64594+ PAGE_SIZE)
64595+ kfree(name_set.n_hash);
64596+ else
64597+ vfree(name_set.n_hash);
64598+ }
64599+
64600+ if (inodev_set.i_hash) {
64601+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
64602+ PAGE_SIZE)
64603+ kfree(inodev_set.i_hash);
64604+ else
64605+ vfree(inodev_set.i_hash);
64606+ }
64607+
64608+ gr_free_uidset();
64609+
64610+ memset(&name_set, 0, sizeof (struct name_db));
64611+ memset(&inodev_set, 0, sizeof (struct inodev_db));
64612+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
64613+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
64614+
64615+ default_role = NULL;
64616+ kernel_role = NULL;
64617+ role_list = NULL;
64618+
64619+ return;
64620+}
64621+
64622+static struct acl_subject_label *
64623+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
64624+
64625+static int alloc_and_copy_string(char **name, unsigned int maxlen)
64626+{
64627+ unsigned int len = strnlen_user(*name, maxlen);
64628+ char *tmp;
64629+
64630+ if (!len || len >= maxlen)
64631+ return -EINVAL;
64632+
64633+ if ((tmp = (char *) acl_alloc(len)) == NULL)
64634+ return -ENOMEM;
64635+
64636+ if (copy_from_user(tmp, *name, len))
64637+ return -EFAULT;
64638+
64639+ tmp[len-1] = '\0';
64640+ *name = tmp;
64641+
64642+ return 0;
64643+}
64644+
64645+static int
64646+copy_user_glob(struct acl_object_label *obj)
64647+{
64648+ struct acl_object_label *g_tmp, **guser;
64649+ int error;
64650+
64651+ if (obj->globbed == NULL)
64652+ return 0;
64653+
64654+ guser = &obj->globbed;
64655+ while (*guser) {
64656+ g_tmp = (struct acl_object_label *)
64657+ acl_alloc(sizeof (struct acl_object_label));
64658+ if (g_tmp == NULL)
64659+ return -ENOMEM;
64660+
64661+ if (copy_acl_object_label(g_tmp, *guser))
64662+ return -EFAULT;
64663+
64664+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
64665+ if (error)
64666+ return error;
64667+
64668+ *guser = g_tmp;
64669+ guser = &(g_tmp->next);
64670+ }
64671+
64672+ return 0;
64673+}
64674+
64675+static int
64676+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
64677+ struct acl_role_label *role)
64678+{
64679+ struct acl_object_label *o_tmp;
64680+ int ret;
64681+
64682+ while (userp) {
64683+ if ((o_tmp = (struct acl_object_label *)
64684+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
64685+ return -ENOMEM;
64686+
64687+ if (copy_acl_object_label(o_tmp, userp))
64688+ return -EFAULT;
64689+
64690+ userp = o_tmp->prev;
64691+
64692+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
64693+ if (ret)
64694+ return ret;
64695+
64696+ insert_acl_obj_label(o_tmp, subj);
64697+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
64698+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
64699+ return -ENOMEM;
64700+
64701+ ret = copy_user_glob(o_tmp);
64702+ if (ret)
64703+ return ret;
64704+
64705+ if (o_tmp->nested) {
64706+ int already_copied;
64707+
64708+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
64709+ if (IS_ERR(o_tmp->nested))
64710+ return PTR_ERR(o_tmp->nested);
64711+
64712+ /* insert into nested subject list if we haven't copied this one yet
64713+ to prevent duplicate entries */
64714+ if (!already_copied) {
64715+ o_tmp->nested->next = role->hash->first;
64716+ role->hash->first = o_tmp->nested;
64717+ }
64718+ }
64719+ }
64720+
64721+ return 0;
64722+}
64723+
64724+static __u32
64725+count_user_subjs(struct acl_subject_label *userp)
64726+{
64727+ struct acl_subject_label s_tmp;
64728+ __u32 num = 0;
64729+
64730+ while (userp) {
64731+ if (copy_acl_subject_label(&s_tmp, userp))
64732+ break;
64733+
64734+ userp = s_tmp.prev;
64735+ }
64736+
64737+ return num;
64738+}
64739+
64740+static int
64741+copy_user_allowedips(struct acl_role_label *rolep)
64742+{
64743+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
64744+
64745+ ruserip = rolep->allowed_ips;
64746+
64747+ while (ruserip) {
64748+ rlast = rtmp;
64749+
64750+ if ((rtmp = (struct role_allowed_ip *)
64751+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
64752+ return -ENOMEM;
64753+
64754+ if (copy_role_allowed_ip(rtmp, ruserip))
64755+ return -EFAULT;
64756+
64757+ ruserip = rtmp->prev;
64758+
64759+ if (!rlast) {
64760+ rtmp->prev = NULL;
64761+ rolep->allowed_ips = rtmp;
64762+ } else {
64763+ rlast->next = rtmp;
64764+ rtmp->prev = rlast;
64765+ }
64766+
64767+ if (!ruserip)
64768+ rtmp->next = NULL;
64769+ }
64770+
64771+ return 0;
64772+}
64773+
64774+static int
64775+copy_user_transitions(struct acl_role_label *rolep)
64776+{
64777+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
64778+ int error;
64779+
64780+ rusertp = rolep->transitions;
64781+
64782+ while (rusertp) {
64783+ rlast = rtmp;
64784+
64785+ if ((rtmp = (struct role_transition *)
64786+ acl_alloc(sizeof (struct role_transition))) == NULL)
64787+ return -ENOMEM;
64788+
64789+ if (copy_role_transition(rtmp, rusertp))
64790+ return -EFAULT;
64791+
64792+ rusertp = rtmp->prev;
64793+
64794+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
64795+ if (error)
64796+ return error;
64797+
64798+ if (!rlast) {
64799+ rtmp->prev = NULL;
64800+ rolep->transitions = rtmp;
64801+ } else {
64802+ rlast->next = rtmp;
64803+ rtmp->prev = rlast;
64804+ }
64805+
64806+ if (!rusertp)
64807+ rtmp->next = NULL;
64808+ }
64809+
64810+ return 0;
64811+}
64812+
64813+static __u32 count_user_objs(const struct acl_object_label __user *userp)
64814+{
64815+ struct acl_object_label o_tmp;
64816+ __u32 num = 0;
64817+
64818+ while (userp) {
64819+ if (copy_acl_object_label(&o_tmp, userp))
64820+ break;
64821+
64822+ userp = o_tmp.prev;
64823+ num++;
64824+ }
64825+
64826+ return num;
64827+}
64828+
64829+static struct acl_subject_label *
64830+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
64831+{
64832+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
64833+ __u32 num_objs;
64834+ struct acl_ip_label **i_tmp, *i_utmp2;
64835+ struct gr_hash_struct ghash;
64836+ struct subject_map *subjmap;
64837+ unsigned int i_num;
64838+ int err;
64839+
64840+ if (already_copied != NULL)
64841+ *already_copied = 0;
64842+
64843+ s_tmp = lookup_subject_map(userp);
64844+
64845+ /* we've already copied this subject into the kernel, just return
64846+ the reference to it, and don't copy it over again
64847+ */
64848+ if (s_tmp) {
64849+ if (already_copied != NULL)
64850+ *already_copied = 1;
64851+ return(s_tmp);
64852+ }
64853+
64854+ if ((s_tmp = (struct acl_subject_label *)
64855+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
64856+ return ERR_PTR(-ENOMEM);
64857+
64858+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
64859+ if (subjmap == NULL)
64860+ return ERR_PTR(-ENOMEM);
64861+
64862+ subjmap->user = userp;
64863+ subjmap->kernel = s_tmp;
64864+ insert_subj_map_entry(subjmap);
64865+
64866+ if (copy_acl_subject_label(s_tmp, userp))
64867+ return ERR_PTR(-EFAULT);
64868+
64869+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
64870+ if (err)
64871+ return ERR_PTR(err);
64872+
64873+ if (!strcmp(s_tmp->filename, "/"))
64874+ role->root_label = s_tmp;
64875+
64876+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
64877+ return ERR_PTR(-EFAULT);
64878+
64879+ /* copy user and group transition tables */
64880+
64881+ if (s_tmp->user_trans_num) {
64882+ uid_t *uidlist;
64883+
64884+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
64885+ if (uidlist == NULL)
64886+ return ERR_PTR(-ENOMEM);
64887+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
64888+ return ERR_PTR(-EFAULT);
64889+
64890+ s_tmp->user_transitions = uidlist;
64891+ }
64892+
64893+ if (s_tmp->group_trans_num) {
64894+ gid_t *gidlist;
64895+
64896+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
64897+ if (gidlist == NULL)
64898+ return ERR_PTR(-ENOMEM);
64899+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
64900+ return ERR_PTR(-EFAULT);
64901+
64902+ s_tmp->group_transitions = gidlist;
64903+ }
64904+
64905+ /* set up object hash table */
64906+ num_objs = count_user_objs(ghash.first);
64907+
64908+ s_tmp->obj_hash_size = num_objs;
64909+ s_tmp->obj_hash =
64910+ (struct acl_object_label **)
64911+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
64912+
64913+ if (!s_tmp->obj_hash)
64914+ return ERR_PTR(-ENOMEM);
64915+
64916+ memset(s_tmp->obj_hash, 0,
64917+ s_tmp->obj_hash_size *
64918+ sizeof (struct acl_object_label *));
64919+
64920+ /* add in objects */
64921+ err = copy_user_objs(ghash.first, s_tmp, role);
64922+
64923+ if (err)
64924+ return ERR_PTR(err);
64925+
64926+ /* set pointer for parent subject */
64927+ if (s_tmp->parent_subject) {
64928+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
64929+
64930+ if (IS_ERR(s_tmp2))
64931+ return s_tmp2;
64932+
64933+ s_tmp->parent_subject = s_tmp2;
64934+ }
64935+
64936+ /* add in ip acls */
64937+
64938+ if (!s_tmp->ip_num) {
64939+ s_tmp->ips = NULL;
64940+ goto insert;
64941+ }
64942+
64943+ i_tmp =
64944+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
64945+ sizeof (struct acl_ip_label *));
64946+
64947+ if (!i_tmp)
64948+ return ERR_PTR(-ENOMEM);
64949+
64950+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
64951+ *(i_tmp + i_num) =
64952+ (struct acl_ip_label *)
64953+ acl_alloc(sizeof (struct acl_ip_label));
64954+ if (!*(i_tmp + i_num))
64955+ return ERR_PTR(-ENOMEM);
64956+
64957+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
64958+ return ERR_PTR(-EFAULT);
64959+
64960+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
64961+ return ERR_PTR(-EFAULT);
64962+
64963+ if ((*(i_tmp + i_num))->iface == NULL)
64964+ continue;
64965+
64966+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
64967+ if (err)
64968+ return ERR_PTR(err);
64969+ }
64970+
64971+ s_tmp->ips = i_tmp;
64972+
64973+insert:
64974+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
64975+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
64976+ return ERR_PTR(-ENOMEM);
64977+
64978+ return s_tmp;
64979+}
64980+
64981+static int
64982+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
64983+{
64984+ struct acl_subject_label s_pre;
64985+ struct acl_subject_label * ret;
64986+ int err;
64987+
64988+ while (userp) {
64989+ if (copy_acl_subject_label(&s_pre, userp))
64990+ return -EFAULT;
64991+
64992+ ret = do_copy_user_subj(userp, role, NULL);
64993+
64994+ err = PTR_ERR(ret);
64995+ if (IS_ERR(ret))
64996+ return err;
64997+
64998+ insert_acl_subj_label(ret, role);
64999+
65000+ userp = s_pre.prev;
65001+ }
65002+
65003+ return 0;
65004+}
65005+
65006+static int
65007+copy_user_acl(struct gr_arg *arg)
65008+{
65009+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
65010+ struct acl_subject_label *subj_list;
65011+ struct sprole_pw *sptmp;
65012+ struct gr_hash_struct *ghash;
65013+ uid_t *domainlist;
65014+ unsigned int r_num;
65015+ int err = 0;
65016+ __u16 i;
65017+ __u32 num_subjs;
65018+
65019+ /* we need a default and kernel role */
65020+ if (arg->role_db.num_roles < 2)
65021+ return -EINVAL;
65022+
65023+ /* copy special role authentication info from userspace */
65024+
65025+ num_sprole_pws = arg->num_sprole_pws;
65026+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
65027+
65028+ if (!acl_special_roles && num_sprole_pws)
65029+ return -ENOMEM;
65030+
65031+ for (i = 0; i < num_sprole_pws; i++) {
65032+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
65033+ if (!sptmp)
65034+ return -ENOMEM;
65035+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
65036+ return -EFAULT;
65037+
65038+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
65039+ if (err)
65040+ return err;
65041+
65042+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65043+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
65044+#endif
65045+
65046+ acl_special_roles[i] = sptmp;
65047+ }
65048+
65049+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
65050+
65051+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
65052+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
65053+
65054+ if (!r_tmp)
65055+ return -ENOMEM;
65056+
65057+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
65058+ return -EFAULT;
65059+
65060+ if (copy_acl_role_label(r_tmp, r_utmp2))
65061+ return -EFAULT;
65062+
65063+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
65064+ if (err)
65065+ return err;
65066+
65067+ if (!strcmp(r_tmp->rolename, "default")
65068+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
65069+ default_role = r_tmp;
65070+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
65071+ kernel_role = r_tmp;
65072+ }
65073+
65074+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
65075+ return -ENOMEM;
65076+
65077+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
65078+ return -EFAULT;
65079+
65080+ r_tmp->hash = ghash;
65081+
65082+ num_subjs = count_user_subjs(r_tmp->hash->first);
65083+
65084+ r_tmp->subj_hash_size = num_subjs;
65085+ r_tmp->subj_hash =
65086+ (struct acl_subject_label **)
65087+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
65088+
65089+ if (!r_tmp->subj_hash)
65090+ return -ENOMEM;
65091+
65092+ err = copy_user_allowedips(r_tmp);
65093+ if (err)
65094+ return err;
65095+
65096+ /* copy domain info */
65097+ if (r_tmp->domain_children != NULL) {
65098+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
65099+ if (domainlist == NULL)
65100+ return -ENOMEM;
65101+
65102+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
65103+ return -EFAULT;
65104+
65105+ r_tmp->domain_children = domainlist;
65106+ }
65107+
65108+ err = copy_user_transitions(r_tmp);
65109+ if (err)
65110+ return err;
65111+
65112+ memset(r_tmp->subj_hash, 0,
65113+ r_tmp->subj_hash_size *
65114+ sizeof (struct acl_subject_label *));
65115+
65116+ /* acquire the list of subjects, then NULL out
65117+ the list prior to parsing the subjects for this role,
65118+ as during this parsing the list is replaced with a list
65119+ of *nested* subjects for the role
65120+ */
65121+ subj_list = r_tmp->hash->first;
65122+
65123+ /* set nested subject list to null */
65124+ r_tmp->hash->first = NULL;
65125+
65126+ err = copy_user_subjs(subj_list, r_tmp);
65127+
65128+ if (err)
65129+ return err;
65130+
65131+ insert_acl_role_label(r_tmp);
65132+ }
65133+
65134+ if (default_role == NULL || kernel_role == NULL)
65135+ return -EINVAL;
65136+
65137+ return err;
65138+}
65139+
65140+static int
65141+gracl_init(struct gr_arg *args)
65142+{
65143+ int error = 0;
65144+
65145+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
65146+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
65147+
65148+ if (init_variables(args)) {
65149+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
65150+ error = -ENOMEM;
65151+ free_variables();
65152+ goto out;
65153+ }
65154+
65155+ error = copy_user_acl(args);
65156+ free_init_variables();
65157+ if (error) {
65158+ free_variables();
65159+ goto out;
65160+ }
65161+
65162+ if ((error = gr_set_acls(0))) {
65163+ free_variables();
65164+ goto out;
65165+ }
65166+
65167+ pax_open_kernel();
65168+ gr_status |= GR_READY;
65169+ pax_close_kernel();
65170+
65171+ out:
65172+ return error;
65173+}
65174+
65175+/* derived from glibc fnmatch() 0: match, 1: no match*/
65176+
65177+static int
65178+glob_match(const char *p, const char *n)
65179+{
65180+ char c;
65181+
65182+ while ((c = *p++) != '\0') {
65183+ switch (c) {
65184+ case '?':
65185+ if (*n == '\0')
65186+ return 1;
65187+ else if (*n == '/')
65188+ return 1;
65189+ break;
65190+ case '\\':
65191+ if (*n != c)
65192+ return 1;
65193+ break;
65194+ case '*':
65195+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
65196+ if (*n == '/')
65197+ return 1;
65198+ else if (c == '?') {
65199+ if (*n == '\0')
65200+ return 1;
65201+ else
65202+ ++n;
65203+ }
65204+ }
65205+ if (c == '\0') {
65206+ return 0;
65207+ } else {
65208+ const char *endp;
65209+
65210+ if ((endp = strchr(n, '/')) == NULL)
65211+ endp = n + strlen(n);
65212+
65213+ if (c == '[') {
65214+ for (--p; n < endp; ++n)
65215+ if (!glob_match(p, n))
65216+ return 0;
65217+ } else if (c == '/') {
65218+ while (*n != '\0' && *n != '/')
65219+ ++n;
65220+ if (*n == '/' && !glob_match(p, n + 1))
65221+ return 0;
65222+ } else {
65223+ for (--p; n < endp; ++n)
65224+ if (*n == c && !glob_match(p, n))
65225+ return 0;
65226+ }
65227+
65228+ return 1;
65229+ }
65230+ case '[':
65231+ {
65232+ int not;
65233+ char cold;
65234+
65235+ if (*n == '\0' || *n == '/')
65236+ return 1;
65237+
65238+ not = (*p == '!' || *p == '^');
65239+ if (not)
65240+ ++p;
65241+
65242+ c = *p++;
65243+ for (;;) {
65244+ unsigned char fn = (unsigned char)*n;
65245+
65246+ if (c == '\0')
65247+ return 1;
65248+ else {
65249+ if (c == fn)
65250+ goto matched;
65251+ cold = c;
65252+ c = *p++;
65253+
65254+ if (c == '-' && *p != ']') {
65255+ unsigned char cend = *p++;
65256+
65257+ if (cend == '\0')
65258+ return 1;
65259+
65260+ if (cold <= fn && fn <= cend)
65261+ goto matched;
65262+
65263+ c = *p++;
65264+ }
65265+ }
65266+
65267+ if (c == ']')
65268+ break;
65269+ }
65270+ if (!not)
65271+ return 1;
65272+ break;
65273+ matched:
65274+ while (c != ']') {
65275+ if (c == '\0')
65276+ return 1;
65277+
65278+ c = *p++;
65279+ }
65280+ if (not)
65281+ return 1;
65282+ }
65283+ break;
65284+ default:
65285+ if (c != *n)
65286+ return 1;
65287+ }
65288+
65289+ ++n;
65290+ }
65291+
65292+ if (*n == '\0')
65293+ return 0;
65294+
65295+ if (*n == '/')
65296+ return 0;
65297+
65298+ return 1;
65299+}
65300+
65301+static struct acl_object_label *
65302+chk_glob_label(struct acl_object_label *globbed,
65303+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
65304+{
65305+ struct acl_object_label *tmp;
65306+
65307+ if (*path == NULL)
65308+ *path = gr_to_filename_nolock(dentry, mnt);
65309+
65310+ tmp = globbed;
65311+
65312+ while (tmp) {
65313+ if (!glob_match(tmp->filename, *path))
65314+ return tmp;
65315+ tmp = tmp->next;
65316+ }
65317+
65318+ return NULL;
65319+}
65320+
65321+static struct acl_object_label *
65322+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
65323+ const ino_t curr_ino, const dev_t curr_dev,
65324+ const struct acl_subject_label *subj, char **path, const int checkglob)
65325+{
65326+ struct acl_subject_label *tmpsubj;
65327+ struct acl_object_label *retval;
65328+ struct acl_object_label *retval2;
65329+
65330+ tmpsubj = (struct acl_subject_label *) subj;
65331+ read_lock(&gr_inode_lock);
65332+ do {
65333+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
65334+ if (retval) {
65335+ if (checkglob && retval->globbed) {
65336+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
65337+ if (retval2)
65338+ retval = retval2;
65339+ }
65340+ break;
65341+ }
65342+ } while ((tmpsubj = tmpsubj->parent_subject));
65343+ read_unlock(&gr_inode_lock);
65344+
65345+ return retval;
65346+}
65347+
65348+static __inline__ struct acl_object_label *
65349+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
65350+ struct dentry *curr_dentry,
65351+ const struct acl_subject_label *subj, char **path, const int checkglob)
65352+{
65353+ int newglob = checkglob;
65354+ ino_t inode;
65355+ dev_t device;
65356+
65357+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
65358+ as we don't want a / * rule to match instead of the / object
65359+ don't do this for create lookups that call this function though, since they're looking up
65360+ on the parent and thus need globbing checks on all paths
65361+ */
65362+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
65363+ newglob = GR_NO_GLOB;
65364+
65365+ spin_lock(&curr_dentry->d_lock);
65366+ inode = curr_dentry->d_inode->i_ino;
65367+ device = __get_dev(curr_dentry);
65368+ spin_unlock(&curr_dentry->d_lock);
65369+
65370+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
65371+}
65372+
65373+#ifdef CONFIG_HUGETLBFS
65374+static inline bool
65375+is_hugetlbfs_mnt(const struct vfsmount *mnt)
65376+{
65377+ int i;
65378+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
65379+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
65380+ return true;
65381+ }
65382+
65383+ return false;
65384+}
65385+#endif
65386+
65387+static struct acl_object_label *
65388+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65389+ const struct acl_subject_label *subj, char *path, const int checkglob)
65390+{
65391+ struct dentry *dentry = (struct dentry *) l_dentry;
65392+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
65393+ struct mount *real_mnt = real_mount(mnt);
65394+ struct acl_object_label *retval;
65395+ struct dentry *parent;
65396+
65397+ br_read_lock(&vfsmount_lock);
65398+ write_seqlock(&rename_lock);
65399+
65400+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
65401+#ifdef CONFIG_NET
65402+ mnt == sock_mnt ||
65403+#endif
65404+#ifdef CONFIG_HUGETLBFS
65405+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
65406+#endif
65407+ /* ignore Eric Biederman */
65408+ IS_PRIVATE(l_dentry->d_inode))) {
65409+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
65410+ goto out;
65411+ }
65412+
65413+ for (;;) {
65414+ if (dentry == real_root.dentry && mnt == real_root.mnt)
65415+ break;
65416+
65417+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
65418+ if (!mnt_has_parent(real_mnt))
65419+ break;
65420+
65421+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65422+ if (retval != NULL)
65423+ goto out;
65424+
65425+ dentry = real_mnt->mnt_mountpoint;
65426+ real_mnt = real_mnt->mnt_parent;
65427+ mnt = &real_mnt->mnt;
65428+ continue;
65429+ }
65430+
65431+ parent = dentry->d_parent;
65432+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65433+ if (retval != NULL)
65434+ goto out;
65435+
65436+ dentry = parent;
65437+ }
65438+
65439+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
65440+
65441+ /* real_root is pinned so we don't have to hold a reference */
65442+ if (retval == NULL)
65443+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
65444+out:
65445+ write_sequnlock(&rename_lock);
65446+ br_read_unlock(&vfsmount_lock);
65447+
65448+ BUG_ON(retval == NULL);
65449+
65450+ return retval;
65451+}
65452+
65453+static __inline__ struct acl_object_label *
65454+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65455+ const struct acl_subject_label *subj)
65456+{
65457+ char *path = NULL;
65458+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
65459+}
65460+
65461+static __inline__ struct acl_object_label *
65462+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65463+ const struct acl_subject_label *subj)
65464+{
65465+ char *path = NULL;
65466+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
65467+}
65468+
65469+static __inline__ struct acl_object_label *
65470+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65471+ const struct acl_subject_label *subj, char *path)
65472+{
65473+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
65474+}
65475+
65476+static struct acl_subject_label *
65477+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
65478+ const struct acl_role_label *role)
65479+{
65480+ struct dentry *dentry = (struct dentry *) l_dentry;
65481+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
65482+ struct mount *real_mnt = real_mount(mnt);
65483+ struct acl_subject_label *retval;
65484+ struct dentry *parent;
65485+
65486+ br_read_lock(&vfsmount_lock);
65487+ write_seqlock(&rename_lock);
65488+
65489+ for (;;) {
65490+ if (dentry == real_root.dentry && mnt == real_root.mnt)
65491+ break;
65492+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
65493+ if (!mnt_has_parent(real_mnt))
65494+ break;
65495+
65496+ spin_lock(&dentry->d_lock);
65497+ read_lock(&gr_inode_lock);
65498+ retval =
65499+ lookup_acl_subj_label(dentry->d_inode->i_ino,
65500+ __get_dev(dentry), role);
65501+ read_unlock(&gr_inode_lock);
65502+ spin_unlock(&dentry->d_lock);
65503+ if (retval != NULL)
65504+ goto out;
65505+
65506+ dentry = real_mnt->mnt_mountpoint;
65507+ real_mnt = real_mnt->mnt_parent;
65508+ mnt = &real_mnt->mnt;
65509+ continue;
65510+ }
65511+
65512+ spin_lock(&dentry->d_lock);
65513+ read_lock(&gr_inode_lock);
65514+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
65515+ __get_dev(dentry), role);
65516+ read_unlock(&gr_inode_lock);
65517+ parent = dentry->d_parent;
65518+ spin_unlock(&dentry->d_lock);
65519+
65520+ if (retval != NULL)
65521+ goto out;
65522+
65523+ dentry = parent;
65524+ }
65525+
65526+ spin_lock(&dentry->d_lock);
65527+ read_lock(&gr_inode_lock);
65528+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
65529+ __get_dev(dentry), role);
65530+ read_unlock(&gr_inode_lock);
65531+ spin_unlock(&dentry->d_lock);
65532+
65533+ if (unlikely(retval == NULL)) {
65534+ /* real_root is pinned, we don't need to hold a reference */
65535+ read_lock(&gr_inode_lock);
65536+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
65537+ __get_dev(real_root.dentry), role);
65538+ read_unlock(&gr_inode_lock);
65539+ }
65540+out:
65541+ write_sequnlock(&rename_lock);
65542+ br_read_unlock(&vfsmount_lock);
65543+
65544+ BUG_ON(retval == NULL);
65545+
65546+ return retval;
65547+}
65548+
65549+static void
65550+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
65551+{
65552+ struct task_struct *task = current;
65553+ const struct cred *cred = current_cred();
65554+
65555+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
65556+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
65557+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
65558+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
65559+
65560+ return;
65561+}
65562+
65563+static void
65564+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
65565+{
65566+ struct task_struct *task = current;
65567+ const struct cred *cred = current_cred();
65568+
65569+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
65570+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
65571+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
65572+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
65573+
65574+ return;
65575+}
65576+
65577+static void
65578+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
65579+{
65580+ struct task_struct *task = current;
65581+ const struct cred *cred = current_cred();
65582+
65583+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
65584+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
65585+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
65586+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
65587+
65588+ return;
65589+}
65590+
65591+__u32
65592+gr_search_file(const struct dentry * dentry, const __u32 mode,
65593+ const struct vfsmount * mnt)
65594+{
65595+ __u32 retval = mode;
65596+ struct acl_subject_label *curracl;
65597+ struct acl_object_label *currobj;
65598+
65599+ if (unlikely(!(gr_status & GR_READY)))
65600+ return (mode & ~GR_AUDITS);
65601+
65602+ curracl = current->acl;
65603+
65604+ currobj = chk_obj_label(dentry, mnt, curracl);
65605+ retval = currobj->mode & mode;
65606+
65607+ /* if we're opening a specified transfer file for writing
65608+ (e.g. /dev/initctl), then transfer our role to init
65609+ */
65610+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
65611+ current->role->roletype & GR_ROLE_PERSIST)) {
65612+ struct task_struct *task = init_pid_ns.child_reaper;
65613+
65614+ if (task->role != current->role) {
65615+ task->acl_sp_role = 0;
65616+ task->acl_role_id = current->acl_role_id;
65617+ task->role = current->role;
65618+ rcu_read_lock();
65619+ read_lock(&grsec_exec_file_lock);
65620+ gr_apply_subject_to_task(task);
65621+ read_unlock(&grsec_exec_file_lock);
65622+ rcu_read_unlock();
65623+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
65624+ }
65625+ }
65626+
65627+ if (unlikely
65628+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
65629+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
65630+ __u32 new_mode = mode;
65631+
65632+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
65633+
65634+ retval = new_mode;
65635+
65636+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
65637+ new_mode |= GR_INHERIT;
65638+
65639+ if (!(mode & GR_NOLEARN))
65640+ gr_log_learn(dentry, mnt, new_mode);
65641+ }
65642+
65643+ return retval;
65644+}
65645+
65646+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
65647+ const struct dentry *parent,
65648+ const struct vfsmount *mnt)
65649+{
65650+ struct name_entry *match;
65651+ struct acl_object_label *matchpo;
65652+ struct acl_subject_label *curracl;
65653+ char *path;
65654+
65655+ if (unlikely(!(gr_status & GR_READY)))
65656+ return NULL;
65657+
65658+ preempt_disable();
65659+ path = gr_to_filename_rbac(new_dentry, mnt);
65660+ match = lookup_name_entry_create(path);
65661+
65662+ curracl = current->acl;
65663+
65664+ if (match) {
65665+ read_lock(&gr_inode_lock);
65666+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
65667+ read_unlock(&gr_inode_lock);
65668+
65669+ if (matchpo) {
65670+ preempt_enable();
65671+ return matchpo;
65672+ }
65673+ }
65674+
65675+ // lookup parent
65676+
65677+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
65678+
65679+ preempt_enable();
65680+ return matchpo;
65681+}
65682+
65683+__u32
65684+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
65685+ const struct vfsmount * mnt, const __u32 mode)
65686+{
65687+ struct acl_object_label *matchpo;
65688+ __u32 retval;
65689+
65690+ if (unlikely(!(gr_status & GR_READY)))
65691+ return (mode & ~GR_AUDITS);
65692+
65693+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
65694+
65695+ retval = matchpo->mode & mode;
65696+
65697+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
65698+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
65699+ __u32 new_mode = mode;
65700+
65701+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
65702+
65703+ gr_log_learn(new_dentry, mnt, new_mode);
65704+ return new_mode;
65705+ }
65706+
65707+ return retval;
65708+}
65709+
65710+__u32
65711+gr_check_link(const struct dentry * new_dentry,
65712+ const struct dentry * parent_dentry,
65713+ const struct vfsmount * parent_mnt,
65714+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
65715+{
65716+ struct acl_object_label *obj;
65717+ __u32 oldmode, newmode;
65718+ __u32 needmode;
65719+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
65720+ GR_DELETE | GR_INHERIT;
65721+
65722+ if (unlikely(!(gr_status & GR_READY)))
65723+ return (GR_CREATE | GR_LINK);
65724+
65725+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
65726+ oldmode = obj->mode;
65727+
65728+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
65729+ newmode = obj->mode;
65730+
65731+ needmode = newmode & checkmodes;
65732+
65733+ // old name for hardlink must have at least the permissions of the new name
65734+ if ((oldmode & needmode) != needmode)
65735+ goto bad;
65736+
65737+ // if old name had restrictions/auditing, make sure the new name does as well
65738+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
65739+
65740+ // don't allow hardlinking of suid/sgid/fcapped files without permission
65741+ if (is_privileged_binary(old_dentry))
65742+ needmode |= GR_SETID;
65743+
65744+ if ((newmode & needmode) != needmode)
65745+ goto bad;
65746+
65747+ // enforce minimum permissions
65748+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
65749+ return newmode;
65750+bad:
65751+ needmode = oldmode;
65752+ if (is_privileged_binary(old_dentry))
65753+ needmode |= GR_SETID;
65754+
65755+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
65756+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
65757+ return (GR_CREATE | GR_LINK);
65758+ } else if (newmode & GR_SUPPRESS)
65759+ return GR_SUPPRESS;
65760+ else
65761+ return 0;
65762+}
65763+
65764+int
65765+gr_check_hidden_task(const struct task_struct *task)
65766+{
65767+ if (unlikely(!(gr_status & GR_READY)))
65768+ return 0;
65769+
65770+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
65771+ return 1;
65772+
65773+ return 0;
65774+}
65775+
65776+int
65777+gr_check_protected_task(const struct task_struct *task)
65778+{
65779+ if (unlikely(!(gr_status & GR_READY) || !task))
65780+ return 0;
65781+
65782+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65783+ task->acl != current->acl)
65784+ return 1;
65785+
65786+ return 0;
65787+}
65788+
65789+int
65790+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
65791+{
65792+ struct task_struct *p;
65793+ int ret = 0;
65794+
65795+ if (unlikely(!(gr_status & GR_READY) || !pid))
65796+ return ret;
65797+
65798+ read_lock(&tasklist_lock);
65799+ do_each_pid_task(pid, type, p) {
65800+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
65801+ p->acl != current->acl) {
65802+ ret = 1;
65803+ goto out;
65804+ }
65805+ } while_each_pid_task(pid, type, p);
65806+out:
65807+ read_unlock(&tasklist_lock);
65808+
65809+ return ret;
65810+}
65811+
65812+void
65813+gr_copy_label(struct task_struct *tsk)
65814+{
65815+ tsk->signal->used_accept = 0;
65816+ tsk->acl_sp_role = 0;
65817+ tsk->acl_role_id = current->acl_role_id;
65818+ tsk->acl = current->acl;
65819+ tsk->role = current->role;
65820+ tsk->signal->curr_ip = current->signal->curr_ip;
65821+ tsk->signal->saved_ip = current->signal->saved_ip;
65822+ if (current->exec_file)
65823+ get_file(current->exec_file);
65824+ tsk->exec_file = current->exec_file;
65825+ tsk->is_writable = current->is_writable;
65826+ if (unlikely(current->signal->used_accept)) {
65827+ current->signal->curr_ip = 0;
65828+ current->signal->saved_ip = 0;
65829+ }
65830+
65831+ return;
65832+}
65833+
65834+static void
65835+gr_set_proc_res(struct task_struct *task)
65836+{
65837+ struct acl_subject_label *proc;
65838+ unsigned short i;
65839+
65840+ proc = task->acl;
65841+
65842+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
65843+ return;
65844+
65845+ for (i = 0; i < RLIM_NLIMITS; i++) {
65846+ if (!(proc->resmask & (1U << i)))
65847+ continue;
65848+
65849+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
65850+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
65851+
65852+ if (i == RLIMIT_CPU)
65853+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
65854+ }
65855+
65856+ return;
65857+}
65858+
65859+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
65860+
65861+int
65862+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
65863+{
65864+ unsigned int i;
65865+ __u16 num;
65866+ uid_t *uidlist;
65867+ uid_t curuid;
65868+ int realok = 0;
65869+ int effectiveok = 0;
65870+ int fsok = 0;
65871+ uid_t globalreal, globaleffective, globalfs;
65872+
65873+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
65874+ struct user_struct *user;
65875+
65876+ if (!uid_valid(real))
65877+ goto skipit;
65878+
65879+ /* find user based on global namespace */
65880+
65881+ globalreal = GR_GLOBAL_UID(real);
65882+
65883+ user = find_user(make_kuid(&init_user_ns, globalreal));
65884+ if (user == NULL)
65885+ goto skipit;
65886+
65887+ if (gr_process_kernel_setuid_ban(user)) {
65888+ /* for find_user */
65889+ free_uid(user);
65890+ return 1;
65891+ }
65892+
65893+ /* for find_user */
65894+ free_uid(user);
65895+
65896+skipit:
65897+#endif
65898+
65899+ if (unlikely(!(gr_status & GR_READY)))
65900+ return 0;
65901+
65902+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65903+ gr_log_learn_uid_change(real, effective, fs);
65904+
65905+ num = current->acl->user_trans_num;
65906+ uidlist = current->acl->user_transitions;
65907+
65908+ if (uidlist == NULL)
65909+ return 0;
65910+
65911+ if (!uid_valid(real)) {
65912+ realok = 1;
65913+ globalreal = (uid_t)-1;
65914+ } else {
65915+ globalreal = GR_GLOBAL_UID(real);
65916+ }
65917+ if (!uid_valid(effective)) {
65918+ effectiveok = 1;
65919+ globaleffective = (uid_t)-1;
65920+ } else {
65921+ globaleffective = GR_GLOBAL_UID(effective);
65922+ }
65923+ if (!uid_valid(fs)) {
65924+ fsok = 1;
65925+ globalfs = (uid_t)-1;
65926+ } else {
65927+ globalfs = GR_GLOBAL_UID(fs);
65928+ }
65929+
65930+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
65931+ for (i = 0; i < num; i++) {
65932+ curuid = uidlist[i];
65933+ if (globalreal == curuid)
65934+ realok = 1;
65935+ if (globaleffective == curuid)
65936+ effectiveok = 1;
65937+ if (globalfs == curuid)
65938+ fsok = 1;
65939+ }
65940+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
65941+ for (i = 0; i < num; i++) {
65942+ curuid = uidlist[i];
65943+ if (globalreal == curuid)
65944+ break;
65945+ if (globaleffective == curuid)
65946+ break;
65947+ if (globalfs == curuid)
65948+ break;
65949+ }
65950+ /* not in deny list */
65951+ if (i == num) {
65952+ realok = 1;
65953+ effectiveok = 1;
65954+ fsok = 1;
65955+ }
65956+ }
65957+
65958+ if (realok && effectiveok && fsok)
65959+ return 0;
65960+ else {
65961+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
65962+ return 1;
65963+ }
65964+}
65965+
65966+int
65967+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
65968+{
65969+ unsigned int i;
65970+ __u16 num;
65971+ gid_t *gidlist;
65972+ gid_t curgid;
65973+ int realok = 0;
65974+ int effectiveok = 0;
65975+ int fsok = 0;
65976+ gid_t globalreal, globaleffective, globalfs;
65977+
65978+ if (unlikely(!(gr_status & GR_READY)))
65979+ return 0;
65980+
65981+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65982+ gr_log_learn_gid_change(real, effective, fs);
65983+
65984+ num = current->acl->group_trans_num;
65985+ gidlist = current->acl->group_transitions;
65986+
65987+ if (gidlist == NULL)
65988+ return 0;
65989+
65990+ if (!gid_valid(real)) {
65991+ realok = 1;
65992+ globalreal = (gid_t)-1;
65993+ } else {
65994+ globalreal = GR_GLOBAL_GID(real);
65995+ }
65996+ if (!gid_valid(effective)) {
65997+ effectiveok = 1;
65998+ globaleffective = (gid_t)-1;
65999+ } else {
66000+ globaleffective = GR_GLOBAL_GID(effective);
66001+ }
66002+ if (!gid_valid(fs)) {
66003+ fsok = 1;
66004+ globalfs = (gid_t)-1;
66005+ } else {
66006+ globalfs = GR_GLOBAL_GID(fs);
66007+ }
66008+
66009+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
66010+ for (i = 0; i < num; i++) {
66011+ curgid = gidlist[i];
66012+ if (globalreal == curgid)
66013+ realok = 1;
66014+ if (globaleffective == curgid)
66015+ effectiveok = 1;
66016+ if (globalfs == curgid)
66017+ fsok = 1;
66018+ }
66019+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
66020+ for (i = 0; i < num; i++) {
66021+ curgid = gidlist[i];
66022+ if (globalreal == curgid)
66023+ break;
66024+ if (globaleffective == curgid)
66025+ break;
66026+ if (globalfs == curgid)
66027+ break;
66028+ }
66029+ /* not in deny list */
66030+ if (i == num) {
66031+ realok = 1;
66032+ effectiveok = 1;
66033+ fsok = 1;
66034+ }
66035+ }
66036+
66037+ if (realok && effectiveok && fsok)
66038+ return 0;
66039+ else {
66040+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66041+ return 1;
66042+ }
66043+}
66044+
66045+extern int gr_acl_is_capable(const int cap);
66046+
66047+void
66048+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
66049+{
66050+ struct acl_role_label *role = task->role;
66051+ struct acl_subject_label *subj = NULL;
66052+ struct acl_object_label *obj;
66053+ struct file *filp;
66054+ uid_t uid;
66055+ gid_t gid;
66056+
66057+ if (unlikely(!(gr_status & GR_READY)))
66058+ return;
66059+
66060+ uid = GR_GLOBAL_UID(kuid);
66061+ gid = GR_GLOBAL_GID(kgid);
66062+
66063+ filp = task->exec_file;
66064+
66065+ /* kernel process, we'll give them the kernel role */
66066+ if (unlikely(!filp)) {
66067+ task->role = kernel_role;
66068+ task->acl = kernel_role->root_label;
66069+ return;
66070+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
66071+ role = lookup_acl_role_label(task, uid, gid);
66072+
66073+ /* don't change the role if we're not a privileged process */
66074+ if (role && task->role != role &&
66075+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
66076+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
66077+ return;
66078+
66079+ /* perform subject lookup in possibly new role
66080+ we can use this result below in the case where role == task->role
66081+ */
66082+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
66083+
66084+ /* if we changed uid/gid, but result in the same role
66085+ and are using inheritance, don't lose the inherited subject
66086+ if current subject is other than what normal lookup
66087+ would result in, we arrived via inheritance, don't
66088+ lose subject
66089+ */
66090+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
66091+ (subj == task->acl)))
66092+ task->acl = subj;
66093+
66094+ task->role = role;
66095+
66096+ task->is_writable = 0;
66097+
66098+ /* ignore additional mmap checks for processes that are writable
66099+ by the default ACL */
66100+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66101+ if (unlikely(obj->mode & GR_WRITE))
66102+ task->is_writable = 1;
66103+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66104+ if (unlikely(obj->mode & GR_WRITE))
66105+ task->is_writable = 1;
66106+
66107+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66108+ 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);
66109+#endif
66110+
66111+ gr_set_proc_res(task);
66112+
66113+ return;
66114+}
66115+
66116+int
66117+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
66118+ const int unsafe_flags)
66119+{
66120+ struct task_struct *task = current;
66121+ struct acl_subject_label *newacl;
66122+ struct acl_object_label *obj;
66123+ __u32 retmode;
66124+
66125+ if (unlikely(!(gr_status & GR_READY)))
66126+ return 0;
66127+
66128+ newacl = chk_subj_label(dentry, mnt, task->role);
66129+
66130+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
66131+ did an exec
66132+ */
66133+ rcu_read_lock();
66134+ read_lock(&tasklist_lock);
66135+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
66136+ (task->parent->acl->mode & GR_POVERRIDE))) {
66137+ read_unlock(&tasklist_lock);
66138+ rcu_read_unlock();
66139+ goto skip_check;
66140+ }
66141+ read_unlock(&tasklist_lock);
66142+ rcu_read_unlock();
66143+
66144+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
66145+ !(task->role->roletype & GR_ROLE_GOD) &&
66146+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
66147+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66148+ if (unsafe_flags & LSM_UNSAFE_SHARE)
66149+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
66150+ else
66151+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
66152+ return -EACCES;
66153+ }
66154+
66155+skip_check:
66156+
66157+ obj = chk_obj_label(dentry, mnt, task->acl);
66158+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
66159+
66160+ if (!(task->acl->mode & GR_INHERITLEARN) &&
66161+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
66162+ if (obj->nested)
66163+ task->acl = obj->nested;
66164+ else
66165+ task->acl = newacl;
66166+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
66167+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
66168+
66169+ task->is_writable = 0;
66170+
66171+ /* ignore additional mmap checks for processes that are writable
66172+ by the default ACL */
66173+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
66174+ if (unlikely(obj->mode & GR_WRITE))
66175+ task->is_writable = 1;
66176+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
66177+ if (unlikely(obj->mode & GR_WRITE))
66178+ task->is_writable = 1;
66179+
66180+ gr_set_proc_res(task);
66181+
66182+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66183+ 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);
66184+#endif
66185+ return 0;
66186+}
66187+
66188+/* always called with valid inodev ptr */
66189+static void
66190+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
66191+{
66192+ struct acl_object_label *matchpo;
66193+ struct acl_subject_label *matchps;
66194+ struct acl_subject_label *subj;
66195+ struct acl_role_label *role;
66196+ unsigned int x;
66197+
66198+ FOR_EACH_ROLE_START(role)
66199+ FOR_EACH_SUBJECT_START(role, subj, x)
66200+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
66201+ matchpo->mode |= GR_DELETED;
66202+ FOR_EACH_SUBJECT_END(subj,x)
66203+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
66204+ /* nested subjects aren't in the role's subj_hash table */
66205+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
66206+ matchpo->mode |= GR_DELETED;
66207+ FOR_EACH_NESTED_SUBJECT_END(subj)
66208+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
66209+ matchps->mode |= GR_DELETED;
66210+ FOR_EACH_ROLE_END(role)
66211+
66212+ inodev->nentry->deleted = 1;
66213+
66214+ return;
66215+}
66216+
66217+void
66218+gr_handle_delete(const ino_t ino, const dev_t dev)
66219+{
66220+ struct inodev_entry *inodev;
66221+
66222+ if (unlikely(!(gr_status & GR_READY)))
66223+ return;
66224+
66225+ write_lock(&gr_inode_lock);
66226+ inodev = lookup_inodev_entry(ino, dev);
66227+ if (inodev != NULL)
66228+ do_handle_delete(inodev, ino, dev);
66229+ write_unlock(&gr_inode_lock);
66230+
66231+ return;
66232+}
66233+
66234+static void
66235+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
66236+ const ino_t newinode, const dev_t newdevice,
66237+ struct acl_subject_label *subj)
66238+{
66239+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
66240+ struct acl_object_label *match;
66241+
66242+ match = subj->obj_hash[index];
66243+
66244+ while (match && (match->inode != oldinode ||
66245+ match->device != olddevice ||
66246+ !(match->mode & GR_DELETED)))
66247+ match = match->next;
66248+
66249+ if (match && (match->inode == oldinode)
66250+ && (match->device == olddevice)
66251+ && (match->mode & GR_DELETED)) {
66252+ if (match->prev == NULL) {
66253+ subj->obj_hash[index] = match->next;
66254+ if (match->next != NULL)
66255+ match->next->prev = NULL;
66256+ } else {
66257+ match->prev->next = match->next;
66258+ if (match->next != NULL)
66259+ match->next->prev = match->prev;
66260+ }
66261+ match->prev = NULL;
66262+ match->next = NULL;
66263+ match->inode = newinode;
66264+ match->device = newdevice;
66265+ match->mode &= ~GR_DELETED;
66266+
66267+ insert_acl_obj_label(match, subj);
66268+ }
66269+
66270+ return;
66271+}
66272+
66273+static void
66274+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
66275+ const ino_t newinode, const dev_t newdevice,
66276+ struct acl_role_label *role)
66277+{
66278+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
66279+ struct acl_subject_label *match;
66280+
66281+ match = role->subj_hash[index];
66282+
66283+ while (match && (match->inode != oldinode ||
66284+ match->device != olddevice ||
66285+ !(match->mode & GR_DELETED)))
66286+ match = match->next;
66287+
66288+ if (match && (match->inode == oldinode)
66289+ && (match->device == olddevice)
66290+ && (match->mode & GR_DELETED)) {
66291+ if (match->prev == NULL) {
66292+ role->subj_hash[index] = match->next;
66293+ if (match->next != NULL)
66294+ match->next->prev = NULL;
66295+ } else {
66296+ match->prev->next = match->next;
66297+ if (match->next != NULL)
66298+ match->next->prev = match->prev;
66299+ }
66300+ match->prev = NULL;
66301+ match->next = NULL;
66302+ match->inode = newinode;
66303+ match->device = newdevice;
66304+ match->mode &= ~GR_DELETED;
66305+
66306+ insert_acl_subj_label(match, role);
66307+ }
66308+
66309+ return;
66310+}
66311+
66312+static void
66313+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
66314+ const ino_t newinode, const dev_t newdevice)
66315+{
66316+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
66317+ struct inodev_entry *match;
66318+
66319+ match = inodev_set.i_hash[index];
66320+
66321+ while (match && (match->nentry->inode != oldinode ||
66322+ match->nentry->device != olddevice || !match->nentry->deleted))
66323+ match = match->next;
66324+
66325+ if (match && (match->nentry->inode == oldinode)
66326+ && (match->nentry->device == olddevice) &&
66327+ match->nentry->deleted) {
66328+ if (match->prev == NULL) {
66329+ inodev_set.i_hash[index] = match->next;
66330+ if (match->next != NULL)
66331+ match->next->prev = NULL;
66332+ } else {
66333+ match->prev->next = match->next;
66334+ if (match->next != NULL)
66335+ match->next->prev = match->prev;
66336+ }
66337+ match->prev = NULL;
66338+ match->next = NULL;
66339+ match->nentry->inode = newinode;
66340+ match->nentry->device = newdevice;
66341+ match->nentry->deleted = 0;
66342+
66343+ insert_inodev_entry(match);
66344+ }
66345+
66346+ return;
66347+}
66348+
66349+static void
66350+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
66351+{
66352+ struct acl_subject_label *subj;
66353+ struct acl_role_label *role;
66354+ unsigned int x;
66355+
66356+ FOR_EACH_ROLE_START(role)
66357+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
66358+
66359+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
66360+ if ((subj->inode == ino) && (subj->device == dev)) {
66361+ subj->inode = ino;
66362+ subj->device = dev;
66363+ }
66364+ /* nested subjects aren't in the role's subj_hash table */
66365+ update_acl_obj_label(matchn->inode, matchn->device,
66366+ ino, dev, subj);
66367+ FOR_EACH_NESTED_SUBJECT_END(subj)
66368+ FOR_EACH_SUBJECT_START(role, subj, x)
66369+ update_acl_obj_label(matchn->inode, matchn->device,
66370+ ino, dev, subj);
66371+ FOR_EACH_SUBJECT_END(subj,x)
66372+ FOR_EACH_ROLE_END(role)
66373+
66374+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
66375+
66376+ return;
66377+}
66378+
66379+static void
66380+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
66381+ const struct vfsmount *mnt)
66382+{
66383+ ino_t ino = dentry->d_inode->i_ino;
66384+ dev_t dev = __get_dev(dentry);
66385+
66386+ __do_handle_create(matchn, ino, dev);
66387+
66388+ return;
66389+}
66390+
66391+void
66392+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
66393+{
66394+ struct name_entry *matchn;
66395+
66396+ if (unlikely(!(gr_status & GR_READY)))
66397+ return;
66398+
66399+ preempt_disable();
66400+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
66401+
66402+ if (unlikely((unsigned long)matchn)) {
66403+ write_lock(&gr_inode_lock);
66404+ do_handle_create(matchn, dentry, mnt);
66405+ write_unlock(&gr_inode_lock);
66406+ }
66407+ preempt_enable();
66408+
66409+ return;
66410+}
66411+
66412+void
66413+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
66414+{
66415+ struct name_entry *matchn;
66416+
66417+ if (unlikely(!(gr_status & GR_READY)))
66418+ return;
66419+
66420+ preempt_disable();
66421+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
66422+
66423+ if (unlikely((unsigned long)matchn)) {
66424+ write_lock(&gr_inode_lock);
66425+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
66426+ write_unlock(&gr_inode_lock);
66427+ }
66428+ preempt_enable();
66429+
66430+ return;
66431+}
66432+
66433+void
66434+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
66435+ struct dentry *old_dentry,
66436+ struct dentry *new_dentry,
66437+ struct vfsmount *mnt, const __u8 replace)
66438+{
66439+ struct name_entry *matchn;
66440+ struct inodev_entry *inodev;
66441+ struct inode *inode = new_dentry->d_inode;
66442+ ino_t old_ino = old_dentry->d_inode->i_ino;
66443+ dev_t old_dev = __get_dev(old_dentry);
66444+
66445+ /* vfs_rename swaps the name and parent link for old_dentry and
66446+ new_dentry
66447+ at this point, old_dentry has the new name, parent link, and inode
66448+ for the renamed file
66449+ if a file is being replaced by a rename, new_dentry has the inode
66450+ and name for the replaced file
66451+ */
66452+
66453+ if (unlikely(!(gr_status & GR_READY)))
66454+ return;
66455+
66456+ preempt_disable();
66457+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
66458+
66459+ /* we wouldn't have to check d_inode if it weren't for
66460+ NFS silly-renaming
66461+ */
66462+
66463+ write_lock(&gr_inode_lock);
66464+ if (unlikely(replace && inode)) {
66465+ ino_t new_ino = inode->i_ino;
66466+ dev_t new_dev = __get_dev(new_dentry);
66467+
66468+ inodev = lookup_inodev_entry(new_ino, new_dev);
66469+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
66470+ do_handle_delete(inodev, new_ino, new_dev);
66471+ }
66472+
66473+ inodev = lookup_inodev_entry(old_ino, old_dev);
66474+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
66475+ do_handle_delete(inodev, old_ino, old_dev);
66476+
66477+ if (unlikely((unsigned long)matchn))
66478+ do_handle_create(matchn, old_dentry, mnt);
66479+
66480+ write_unlock(&gr_inode_lock);
66481+ preempt_enable();
66482+
66483+ return;
66484+}
66485+
66486+static int
66487+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
66488+ unsigned char **sum)
66489+{
66490+ struct acl_role_label *r;
66491+ struct role_allowed_ip *ipp;
66492+ struct role_transition *trans;
66493+ unsigned int i;
66494+ int found = 0;
66495+ u32 curr_ip = current->signal->curr_ip;
66496+
66497+ current->signal->saved_ip = curr_ip;
66498+
66499+ /* check transition table */
66500+
66501+ for (trans = current->role->transitions; trans; trans = trans->next) {
66502+ if (!strcmp(rolename, trans->rolename)) {
66503+ found = 1;
66504+ break;
66505+ }
66506+ }
66507+
66508+ if (!found)
66509+ return 0;
66510+
66511+ /* handle special roles that do not require authentication
66512+ and check ip */
66513+
66514+ FOR_EACH_ROLE_START(r)
66515+ if (!strcmp(rolename, r->rolename) &&
66516+ (r->roletype & GR_ROLE_SPECIAL)) {
66517+ found = 0;
66518+ if (r->allowed_ips != NULL) {
66519+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
66520+ if ((ntohl(curr_ip) & ipp->netmask) ==
66521+ (ntohl(ipp->addr) & ipp->netmask))
66522+ found = 1;
66523+ }
66524+ } else
66525+ found = 2;
66526+ if (!found)
66527+ return 0;
66528+
66529+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
66530+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
66531+ *salt = NULL;
66532+ *sum = NULL;
66533+ return 1;
66534+ }
66535+ }
66536+ FOR_EACH_ROLE_END(r)
66537+
66538+ for (i = 0; i < num_sprole_pws; i++) {
66539+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
66540+ *salt = acl_special_roles[i]->salt;
66541+ *sum = acl_special_roles[i]->sum;
66542+ return 1;
66543+ }
66544+ }
66545+
66546+ return 0;
66547+}
66548+
66549+static void
66550+assign_special_role(char *rolename)
66551+{
66552+ struct acl_object_label *obj;
66553+ struct acl_role_label *r;
66554+ struct acl_role_label *assigned = NULL;
66555+ struct task_struct *tsk;
66556+ struct file *filp;
66557+
66558+ FOR_EACH_ROLE_START(r)
66559+ if (!strcmp(rolename, r->rolename) &&
66560+ (r->roletype & GR_ROLE_SPECIAL)) {
66561+ assigned = r;
66562+ break;
66563+ }
66564+ FOR_EACH_ROLE_END(r)
66565+
66566+ if (!assigned)
66567+ return;
66568+
66569+ read_lock(&tasklist_lock);
66570+ read_lock(&grsec_exec_file_lock);
66571+
66572+ tsk = current->real_parent;
66573+ if (tsk == NULL)
66574+ goto out_unlock;
66575+
66576+ filp = tsk->exec_file;
66577+ if (filp == NULL)
66578+ goto out_unlock;
66579+
66580+ tsk->is_writable = 0;
66581+
66582+ tsk->acl_sp_role = 1;
66583+ tsk->acl_role_id = ++acl_sp_role_value;
66584+ tsk->role = assigned;
66585+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66586+
66587+ /* ignore additional mmap checks for processes that are writable
66588+ by the default ACL */
66589+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66590+ if (unlikely(obj->mode & GR_WRITE))
66591+ tsk->is_writable = 1;
66592+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66593+ if (unlikely(obj->mode & GR_WRITE))
66594+ tsk->is_writable = 1;
66595+
66596+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66597+ 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));
66598+#endif
66599+
66600+out_unlock:
66601+ read_unlock(&grsec_exec_file_lock);
66602+ read_unlock(&tasklist_lock);
66603+ return;
66604+}
66605+
66606+int gr_check_secure_terminal(struct task_struct *task)
66607+{
66608+ struct task_struct *p, *p2, *p3;
66609+ struct files_struct *files;
66610+ struct fdtable *fdt;
66611+ struct file *our_file = NULL, *file;
66612+ int i;
66613+
66614+ if (task->signal->tty == NULL)
66615+ return 1;
66616+
66617+ files = get_files_struct(task);
66618+ if (files != NULL) {
66619+ rcu_read_lock();
66620+ fdt = files_fdtable(files);
66621+ for (i=0; i < fdt->max_fds; i++) {
66622+ file = fcheck_files(files, i);
66623+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
66624+ get_file(file);
66625+ our_file = file;
66626+ }
66627+ }
66628+ rcu_read_unlock();
66629+ put_files_struct(files);
66630+ }
66631+
66632+ if (our_file == NULL)
66633+ return 1;
66634+
66635+ read_lock(&tasklist_lock);
66636+ do_each_thread(p2, p) {
66637+ files = get_files_struct(p);
66638+ if (files == NULL ||
66639+ (p->signal && p->signal->tty == task->signal->tty)) {
66640+ if (files != NULL)
66641+ put_files_struct(files);
66642+ continue;
66643+ }
66644+ rcu_read_lock();
66645+ fdt = files_fdtable(files);
66646+ for (i=0; i < fdt->max_fds; i++) {
66647+ file = fcheck_files(files, i);
66648+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
66649+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
66650+ p3 = task;
66651+ while (task_pid_nr(p3) > 0) {
66652+ if (p3 == p)
66653+ break;
66654+ p3 = p3->real_parent;
66655+ }
66656+ if (p3 == p)
66657+ break;
66658+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
66659+ gr_handle_alertkill(p);
66660+ rcu_read_unlock();
66661+ put_files_struct(files);
66662+ read_unlock(&tasklist_lock);
66663+ fput(our_file);
66664+ return 0;
66665+ }
66666+ }
66667+ rcu_read_unlock();
66668+ put_files_struct(files);
66669+ } while_each_thread(p2, p);
66670+ read_unlock(&tasklist_lock);
66671+
66672+ fput(our_file);
66673+ return 1;
66674+}
66675+
66676+static int gr_rbac_disable(void *unused)
66677+{
66678+ pax_open_kernel();
66679+ gr_status &= ~GR_READY;
66680+ pax_close_kernel();
66681+
66682+ return 0;
66683+}
66684+
66685+ssize_t
66686+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
66687+{
66688+ struct gr_arg_wrapper uwrap;
66689+ unsigned char *sprole_salt = NULL;
66690+ unsigned char *sprole_sum = NULL;
66691+ int error = 0;
66692+ int error2 = 0;
66693+ size_t req_count = 0;
66694+
66695+ mutex_lock(&gr_dev_mutex);
66696+
66697+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
66698+ error = -EPERM;
66699+ goto out;
66700+ }
66701+
66702+#ifdef CONFIG_COMPAT
66703+ pax_open_kernel();
66704+ if (is_compat_task()) {
66705+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
66706+ copy_gr_arg = &copy_gr_arg_compat;
66707+ copy_acl_object_label = &copy_acl_object_label_compat;
66708+ copy_acl_subject_label = &copy_acl_subject_label_compat;
66709+ copy_acl_role_label = &copy_acl_role_label_compat;
66710+ copy_acl_ip_label = &copy_acl_ip_label_compat;
66711+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
66712+ copy_role_transition = &copy_role_transition_compat;
66713+ copy_sprole_pw = &copy_sprole_pw_compat;
66714+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
66715+ copy_pointer_from_array = &copy_pointer_from_array_compat;
66716+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
66717+ } else {
66718+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
66719+ copy_gr_arg = &copy_gr_arg_normal;
66720+ copy_acl_object_label = &copy_acl_object_label_normal;
66721+ copy_acl_subject_label = &copy_acl_subject_label_normal;
66722+ copy_acl_role_label = &copy_acl_role_label_normal;
66723+ copy_acl_ip_label = &copy_acl_ip_label_normal;
66724+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
66725+ copy_role_transition = &copy_role_transition_normal;
66726+ copy_sprole_pw = &copy_sprole_pw_normal;
66727+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
66728+ copy_pointer_from_array = &copy_pointer_from_array_normal;
66729+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
66730+ }
66731+ pax_close_kernel();
66732+#endif
66733+
66734+ req_count = get_gr_arg_wrapper_size();
66735+
66736+ if (count != req_count) {
66737+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
66738+ error = -EINVAL;
66739+ goto out;
66740+ }
66741+
66742+
66743+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
66744+ gr_auth_expires = 0;
66745+ gr_auth_attempts = 0;
66746+ }
66747+
66748+ error = copy_gr_arg_wrapper(buf, &uwrap);
66749+ if (error)
66750+ goto out;
66751+
66752+ error = copy_gr_arg(uwrap.arg, gr_usermode);
66753+ if (error)
66754+ goto out;
66755+
66756+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
66757+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
66758+ time_after(gr_auth_expires, get_seconds())) {
66759+ error = -EBUSY;
66760+ goto out;
66761+ }
66762+
66763+ /* if non-root trying to do anything other than use a special role,
66764+ do not attempt authentication, do not count towards authentication
66765+ locking
66766+ */
66767+
66768+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
66769+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
66770+ gr_is_global_nonroot(current_uid())) {
66771+ error = -EPERM;
66772+ goto out;
66773+ }
66774+
66775+ /* ensure pw and special role name are null terminated */
66776+
66777+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
66778+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
66779+
66780+ /* Okay.
66781+ * We have our enough of the argument structure..(we have yet
66782+ * to copy_from_user the tables themselves) . Copy the tables
66783+ * only if we need them, i.e. for loading operations. */
66784+
66785+ switch (gr_usermode->mode) {
66786+ case GR_STATUS:
66787+ if (gr_status & GR_READY) {
66788+ error = 1;
66789+ if (!gr_check_secure_terminal(current))
66790+ error = 3;
66791+ } else
66792+ error = 2;
66793+ goto out;
66794+ case GR_SHUTDOWN:
66795+ if ((gr_status & GR_READY)
66796+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
66797+ stop_machine(gr_rbac_disable, NULL, NULL);
66798+ free_variables();
66799+ memset(gr_usermode, 0, sizeof (struct gr_arg));
66800+ memset(gr_system_salt, 0, GR_SALT_LEN);
66801+ memset(gr_system_sum, 0, GR_SHA_LEN);
66802+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
66803+ } else if (gr_status & GR_READY) {
66804+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
66805+ error = -EPERM;
66806+ } else {
66807+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
66808+ error = -EAGAIN;
66809+ }
66810+ break;
66811+ case GR_ENABLE:
66812+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
66813+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
66814+ else {
66815+ if (gr_status & GR_READY)
66816+ error = -EAGAIN;
66817+ else
66818+ error = error2;
66819+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
66820+ }
66821+ break;
66822+ case GR_RELOAD:
66823+ if (!(gr_status & GR_READY)) {
66824+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
66825+ error = -EAGAIN;
66826+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
66827+ stop_machine(gr_rbac_disable, NULL, NULL);
66828+ free_variables();
66829+ error2 = gracl_init(gr_usermode);
66830+ if (!error2)
66831+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
66832+ else {
66833+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
66834+ error = error2;
66835+ }
66836+ } else {
66837+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
66838+ error = -EPERM;
66839+ }
66840+ break;
66841+ case GR_SEGVMOD:
66842+ if (unlikely(!(gr_status & GR_READY))) {
66843+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
66844+ error = -EAGAIN;
66845+ break;
66846+ }
66847+
66848+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
66849+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
66850+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
66851+ struct acl_subject_label *segvacl;
66852+ segvacl =
66853+ lookup_acl_subj_label(gr_usermode->segv_inode,
66854+ gr_usermode->segv_device,
66855+ current->role);
66856+ if (segvacl) {
66857+ segvacl->crashes = 0;
66858+ segvacl->expires = 0;
66859+ }
66860+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
66861+ gr_remove_uid(gr_usermode->segv_uid);
66862+ }
66863+ } else {
66864+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
66865+ error = -EPERM;
66866+ }
66867+ break;
66868+ case GR_SPROLE:
66869+ case GR_SPROLEPAM:
66870+ if (unlikely(!(gr_status & GR_READY))) {
66871+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
66872+ error = -EAGAIN;
66873+ break;
66874+ }
66875+
66876+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
66877+ current->role->expires = 0;
66878+ current->role->auth_attempts = 0;
66879+ }
66880+
66881+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
66882+ time_after(current->role->expires, get_seconds())) {
66883+ error = -EBUSY;
66884+ goto out;
66885+ }
66886+
66887+ if (lookup_special_role_auth
66888+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
66889+ && ((!sprole_salt && !sprole_sum)
66890+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
66891+ char *p = "";
66892+ assign_special_role(gr_usermode->sp_role);
66893+ read_lock(&tasklist_lock);
66894+ if (current->real_parent)
66895+ p = current->real_parent->role->rolename;
66896+ read_unlock(&tasklist_lock);
66897+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
66898+ p, acl_sp_role_value);
66899+ } else {
66900+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
66901+ error = -EPERM;
66902+ if(!(current->role->auth_attempts++))
66903+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
66904+
66905+ goto out;
66906+ }
66907+ break;
66908+ case GR_UNSPROLE:
66909+ if (unlikely(!(gr_status & GR_READY))) {
66910+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
66911+ error = -EAGAIN;
66912+ break;
66913+ }
66914+
66915+ if (current->role->roletype & GR_ROLE_SPECIAL) {
66916+ char *p = "";
66917+ int i = 0;
66918+
66919+ read_lock(&tasklist_lock);
66920+ if (current->real_parent) {
66921+ p = current->real_parent->role->rolename;
66922+ i = current->real_parent->acl_role_id;
66923+ }
66924+ read_unlock(&tasklist_lock);
66925+
66926+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
66927+ gr_set_acls(1);
66928+ } else {
66929+ error = -EPERM;
66930+ goto out;
66931+ }
66932+ break;
66933+ default:
66934+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
66935+ error = -EINVAL;
66936+ break;
66937+ }
66938+
66939+ if (error != -EPERM)
66940+ goto out;
66941+
66942+ if(!(gr_auth_attempts++))
66943+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
66944+
66945+ out:
66946+ mutex_unlock(&gr_dev_mutex);
66947+
66948+ if (!error)
66949+ error = req_count;
66950+
66951+ return error;
66952+}
66953+
66954+/* must be called with
66955+ rcu_read_lock();
66956+ read_lock(&tasklist_lock);
66957+ read_lock(&grsec_exec_file_lock);
66958+*/
66959+int gr_apply_subject_to_task(struct task_struct *task)
66960+{
66961+ struct acl_object_label *obj;
66962+ char *tmpname;
66963+ struct acl_subject_label *tmpsubj;
66964+ struct file *filp;
66965+ struct name_entry *nmatch;
66966+
66967+ filp = task->exec_file;
66968+ if (filp == NULL)
66969+ return 0;
66970+
66971+ /* the following is to apply the correct subject
66972+ on binaries running when the RBAC system
66973+ is enabled, when the binaries have been
66974+ replaced or deleted since their execution
66975+ -----
66976+ when the RBAC system starts, the inode/dev
66977+ from exec_file will be one the RBAC system
66978+ is unaware of. It only knows the inode/dev
66979+ of the present file on disk, or the absence
66980+ of it.
66981+ */
66982+ preempt_disable();
66983+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66984+
66985+ nmatch = lookup_name_entry(tmpname);
66986+ preempt_enable();
66987+ tmpsubj = NULL;
66988+ if (nmatch) {
66989+ if (nmatch->deleted)
66990+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66991+ else
66992+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66993+ if (tmpsubj != NULL)
66994+ task->acl = tmpsubj;
66995+ }
66996+ if (tmpsubj == NULL)
66997+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
66998+ task->role);
66999+ if (task->acl) {
67000+ task->is_writable = 0;
67001+ /* ignore additional mmap checks for processes that are writable
67002+ by the default ACL */
67003+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
67004+ if (unlikely(obj->mode & GR_WRITE))
67005+ task->is_writable = 1;
67006+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67007+ if (unlikely(obj->mode & GR_WRITE))
67008+ task->is_writable = 1;
67009+
67010+ gr_set_proc_res(task);
67011+
67012+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67013+ 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);
67014+#endif
67015+ } else {
67016+ return 1;
67017+ }
67018+
67019+ return 0;
67020+}
67021+
67022+int
67023+gr_set_acls(const int type)
67024+{
67025+ struct task_struct *task, *task2;
67026+ struct acl_role_label *role = current->role;
67027+ __u16 acl_role_id = current->acl_role_id;
67028+ const struct cred *cred;
67029+ int ret;
67030+
67031+ rcu_read_lock();
67032+ read_lock(&tasklist_lock);
67033+ read_lock(&grsec_exec_file_lock);
67034+ do_each_thread(task2, task) {
67035+ /* check to see if we're called from the exit handler,
67036+ if so, only replace ACLs that have inherited the admin
67037+ ACL */
67038+
67039+ if (type && (task->role != role ||
67040+ task->acl_role_id != acl_role_id))
67041+ continue;
67042+
67043+ task->acl_role_id = 0;
67044+ task->acl_sp_role = 0;
67045+
67046+ if (task->exec_file) {
67047+ cred = __task_cred(task);
67048+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
67049+ ret = gr_apply_subject_to_task(task);
67050+ if (ret) {
67051+ read_unlock(&grsec_exec_file_lock);
67052+ read_unlock(&tasklist_lock);
67053+ rcu_read_unlock();
67054+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
67055+ return ret;
67056+ }
67057+ } else {
67058+ // it's a kernel process
67059+ task->role = kernel_role;
67060+ task->acl = kernel_role->root_label;
67061+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
67062+ task->acl->mode &= ~GR_PROCFIND;
67063+#endif
67064+ }
67065+ } while_each_thread(task2, task);
67066+ read_unlock(&grsec_exec_file_lock);
67067+ read_unlock(&tasklist_lock);
67068+ rcu_read_unlock();
67069+
67070+ return 0;
67071+}
67072+
67073+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67074+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67075+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67076+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67077+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67078+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67079+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67080+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67081+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67082+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67083+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67084+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67085+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67086+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67087+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67088+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67089+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67090+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67091+};
67092+
67093+void
67094+gr_learn_resource(const struct task_struct *task,
67095+ const int res, const unsigned long wanted, const int gt)
67096+{
67097+ struct acl_subject_label *acl;
67098+ const struct cred *cred;
67099+
67100+ if (unlikely((gr_status & GR_READY) &&
67101+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67102+ goto skip_reslog;
67103+
67104+ gr_log_resource(task, res, wanted, gt);
67105+skip_reslog:
67106+
67107+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67108+ return;
67109+
67110+ acl = task->acl;
67111+
67112+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67113+ !(acl->resmask & (1U << (unsigned short) res))))
67114+ return;
67115+
67116+ if (wanted >= acl->res[res].rlim_cur) {
67117+ unsigned long res_add;
67118+
67119+ res_add = wanted + res_learn_bumps[res];
67120+
67121+ acl->res[res].rlim_cur = res_add;
67122+
67123+ if (wanted > acl->res[res].rlim_max)
67124+ acl->res[res].rlim_max = res_add;
67125+
67126+ /* only log the subject filename, since resource logging is supported for
67127+ single-subject learning only */
67128+ rcu_read_lock();
67129+ cred = __task_cred(task);
67130+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67131+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67132+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67133+ "", (unsigned long) res, &task->signal->saved_ip);
67134+ rcu_read_unlock();
67135+ }
67136+
67137+ return;
67138+}
67139+EXPORT_SYMBOL(gr_learn_resource);
67140+#endif
67141+
67142+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67143+void
67144+pax_set_initial_flags(struct linux_binprm *bprm)
67145+{
67146+ struct task_struct *task = current;
67147+ struct acl_subject_label *proc;
67148+ unsigned long flags;
67149+
67150+ if (unlikely(!(gr_status & GR_READY)))
67151+ return;
67152+
67153+ flags = pax_get_flags(task);
67154+
67155+ proc = task->acl;
67156+
67157+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67158+ flags &= ~MF_PAX_PAGEEXEC;
67159+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67160+ flags &= ~MF_PAX_SEGMEXEC;
67161+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67162+ flags &= ~MF_PAX_RANDMMAP;
67163+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67164+ flags &= ~MF_PAX_EMUTRAMP;
67165+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67166+ flags &= ~MF_PAX_MPROTECT;
67167+
67168+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67169+ flags |= MF_PAX_PAGEEXEC;
67170+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67171+ flags |= MF_PAX_SEGMEXEC;
67172+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67173+ flags |= MF_PAX_RANDMMAP;
67174+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67175+ flags |= MF_PAX_EMUTRAMP;
67176+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67177+ flags |= MF_PAX_MPROTECT;
67178+
67179+ pax_set_flags(task, flags);
67180+
67181+ return;
67182+}
67183+#endif
67184+
67185+int
67186+gr_handle_proc_ptrace(struct task_struct *task)
67187+{
67188+ struct file *filp;
67189+ struct task_struct *tmp = task;
67190+ struct task_struct *curtemp = current;
67191+ __u32 retmode;
67192+
67193+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67194+ if (unlikely(!(gr_status & GR_READY)))
67195+ return 0;
67196+#endif
67197+
67198+ read_lock(&tasklist_lock);
67199+ read_lock(&grsec_exec_file_lock);
67200+ filp = task->exec_file;
67201+
67202+ while (task_pid_nr(tmp) > 0) {
67203+ if (tmp == curtemp)
67204+ break;
67205+ tmp = tmp->real_parent;
67206+ }
67207+
67208+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67209+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67210+ read_unlock(&grsec_exec_file_lock);
67211+ read_unlock(&tasklist_lock);
67212+ return 1;
67213+ }
67214+
67215+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67216+ if (!(gr_status & GR_READY)) {
67217+ read_unlock(&grsec_exec_file_lock);
67218+ read_unlock(&tasklist_lock);
67219+ return 0;
67220+ }
67221+#endif
67222+
67223+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67224+ read_unlock(&grsec_exec_file_lock);
67225+ read_unlock(&tasklist_lock);
67226+
67227+ if (retmode & GR_NOPTRACE)
67228+ return 1;
67229+
67230+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67231+ && (current->acl != task->acl || (current->acl != current->role->root_label
67232+ && task_pid_nr(current) != task_pid_nr(task))))
67233+ return 1;
67234+
67235+ return 0;
67236+}
67237+
67238+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67239+{
67240+ if (unlikely(!(gr_status & GR_READY)))
67241+ return;
67242+
67243+ if (!(current->role->roletype & GR_ROLE_GOD))
67244+ return;
67245+
67246+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67247+ p->role->rolename, gr_task_roletype_to_char(p),
67248+ p->acl->filename);
67249+}
67250+
67251+int
67252+gr_handle_ptrace(struct task_struct *task, const long request)
67253+{
67254+ struct task_struct *tmp = task;
67255+ struct task_struct *curtemp = current;
67256+ __u32 retmode;
67257+
67258+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67259+ if (unlikely(!(gr_status & GR_READY)))
67260+ return 0;
67261+#endif
67262+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67263+ read_lock(&tasklist_lock);
67264+ while (task_pid_nr(tmp) > 0) {
67265+ if (tmp == curtemp)
67266+ break;
67267+ tmp = tmp->real_parent;
67268+ }
67269+
67270+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67271+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67272+ read_unlock(&tasklist_lock);
67273+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67274+ return 1;
67275+ }
67276+ read_unlock(&tasklist_lock);
67277+ }
67278+
67279+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67280+ if (!(gr_status & GR_READY))
67281+ return 0;
67282+#endif
67283+
67284+ read_lock(&grsec_exec_file_lock);
67285+ if (unlikely(!task->exec_file)) {
67286+ read_unlock(&grsec_exec_file_lock);
67287+ return 0;
67288+ }
67289+
67290+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67291+ read_unlock(&grsec_exec_file_lock);
67292+
67293+ if (retmode & GR_NOPTRACE) {
67294+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67295+ return 1;
67296+ }
67297+
67298+ if (retmode & GR_PTRACERD) {
67299+ switch (request) {
67300+ case PTRACE_SEIZE:
67301+ case PTRACE_POKETEXT:
67302+ case PTRACE_POKEDATA:
67303+ case PTRACE_POKEUSR:
67304+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67305+ case PTRACE_SETREGS:
67306+ case PTRACE_SETFPREGS:
67307+#endif
67308+#ifdef CONFIG_X86
67309+ case PTRACE_SETFPXREGS:
67310+#endif
67311+#ifdef CONFIG_ALTIVEC
67312+ case PTRACE_SETVRREGS:
67313+#endif
67314+ return 1;
67315+ default:
67316+ return 0;
67317+ }
67318+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
67319+ !(current->role->roletype & GR_ROLE_GOD) &&
67320+ (current->acl != task->acl)) {
67321+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67322+ return 1;
67323+ }
67324+
67325+ return 0;
67326+}
67327+
67328+static int is_writable_mmap(const struct file *filp)
67329+{
67330+ struct task_struct *task = current;
67331+ struct acl_object_label *obj, *obj2;
67332+
67333+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67334+ !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))) {
67335+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
67336+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67337+ task->role->root_label);
67338+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67339+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67340+ return 1;
67341+ }
67342+ }
67343+ return 0;
67344+}
67345+
67346+int
67347+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67348+{
67349+ __u32 mode;
67350+
67351+ if (unlikely(!file || !(prot & PROT_EXEC)))
67352+ return 1;
67353+
67354+ if (is_writable_mmap(file))
67355+ return 0;
67356+
67357+ mode =
67358+ gr_search_file(file->f_path.dentry,
67359+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67360+ file->f_path.mnt);
67361+
67362+ if (!gr_tpe_allow(file))
67363+ return 0;
67364+
67365+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67366+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67367+ return 0;
67368+ } else if (unlikely(!(mode & GR_EXEC))) {
67369+ return 0;
67370+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67371+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67372+ return 1;
67373+ }
67374+
67375+ return 1;
67376+}
67377+
67378+int
67379+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67380+{
67381+ __u32 mode;
67382+
67383+ if (unlikely(!file || !(prot & PROT_EXEC)))
67384+ return 1;
67385+
67386+ if (is_writable_mmap(file))
67387+ return 0;
67388+
67389+ mode =
67390+ gr_search_file(file->f_path.dentry,
67391+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67392+ file->f_path.mnt);
67393+
67394+ if (!gr_tpe_allow(file))
67395+ return 0;
67396+
67397+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67398+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67399+ return 0;
67400+ } else if (unlikely(!(mode & GR_EXEC))) {
67401+ return 0;
67402+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67403+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67404+ return 1;
67405+ }
67406+
67407+ return 1;
67408+}
67409+
67410+void
67411+gr_acl_handle_psacct(struct task_struct *task, const long code)
67412+{
67413+ unsigned long runtime;
67414+ unsigned long cputime;
67415+ unsigned int wday, cday;
67416+ __u8 whr, chr;
67417+ __u8 wmin, cmin;
67418+ __u8 wsec, csec;
67419+ struct timespec timeval;
67420+
67421+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67422+ !(task->acl->mode & GR_PROCACCT)))
67423+ return;
67424+
67425+ do_posix_clock_monotonic_gettime(&timeval);
67426+ runtime = timeval.tv_sec - task->start_time.tv_sec;
67427+ wday = runtime / (3600 * 24);
67428+ runtime -= wday * (3600 * 24);
67429+ whr = runtime / 3600;
67430+ runtime -= whr * 3600;
67431+ wmin = runtime / 60;
67432+ runtime -= wmin * 60;
67433+ wsec = runtime;
67434+
67435+ cputime = (task->utime + task->stime) / HZ;
67436+ cday = cputime / (3600 * 24);
67437+ cputime -= cday * (3600 * 24);
67438+ chr = cputime / 3600;
67439+ cputime -= chr * 3600;
67440+ cmin = cputime / 60;
67441+ cputime -= cmin * 60;
67442+ csec = cputime;
67443+
67444+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67445+
67446+ return;
67447+}
67448+
67449+void gr_set_kernel_label(struct task_struct *task)
67450+{
67451+ if (gr_status & GR_READY) {
67452+ task->role = kernel_role;
67453+ task->acl = kernel_role->root_label;
67454+ }
67455+ return;
67456+}
67457+
67458+#ifdef CONFIG_TASKSTATS
67459+int gr_is_taskstats_denied(int pid)
67460+{
67461+ struct task_struct *task;
67462+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67463+ const struct cred *cred;
67464+#endif
67465+ int ret = 0;
67466+
67467+ /* restrict taskstats viewing to un-chrooted root users
67468+ who have the 'view' subject flag if the RBAC system is enabled
67469+ */
67470+
67471+ rcu_read_lock();
67472+ read_lock(&tasklist_lock);
67473+ task = find_task_by_vpid(pid);
67474+ if (task) {
67475+#ifdef CONFIG_GRKERNSEC_CHROOT
67476+ if (proc_is_chrooted(task))
67477+ ret = -EACCES;
67478+#endif
67479+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67480+ cred = __task_cred(task);
67481+#ifdef CONFIG_GRKERNSEC_PROC_USER
67482+ if (gr_is_global_nonroot(cred->uid))
67483+ ret = -EACCES;
67484+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67485+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67486+ ret = -EACCES;
67487+#endif
67488+#endif
67489+ if (gr_status & GR_READY) {
67490+ if (!(task->acl->mode & GR_VIEW))
67491+ ret = -EACCES;
67492+ }
67493+ } else
67494+ ret = -ENOENT;
67495+
67496+ read_unlock(&tasklist_lock);
67497+ rcu_read_unlock();
67498+
67499+ return ret;
67500+}
67501+#endif
67502+
67503+/* AUXV entries are filled via a descendant of search_binary_handler
67504+ after we've already applied the subject for the target
67505+*/
67506+int gr_acl_enable_at_secure(void)
67507+{
67508+ if (unlikely(!(gr_status & GR_READY)))
67509+ return 0;
67510+
67511+ if (current->acl->mode & GR_ATSECURE)
67512+ return 1;
67513+
67514+ return 0;
67515+}
67516+
67517+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
67518+{
67519+ struct task_struct *task = current;
67520+ struct dentry *dentry = file->f_path.dentry;
67521+ struct vfsmount *mnt = file->f_path.mnt;
67522+ struct acl_object_label *obj, *tmp;
67523+ struct acl_subject_label *subj;
67524+ unsigned int bufsize;
67525+ int is_not_root;
67526+ char *path;
67527+ dev_t dev = __get_dev(dentry);
67528+
67529+ if (unlikely(!(gr_status & GR_READY)))
67530+ return 1;
67531+
67532+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67533+ return 1;
67534+
67535+ /* ignore Eric Biederman */
67536+ if (IS_PRIVATE(dentry->d_inode))
67537+ return 1;
67538+
67539+ subj = task->acl;
67540+ read_lock(&gr_inode_lock);
67541+ do {
67542+ obj = lookup_acl_obj_label(ino, dev, subj);
67543+ if (obj != NULL) {
67544+ read_unlock(&gr_inode_lock);
67545+ return (obj->mode & GR_FIND) ? 1 : 0;
67546+ }
67547+ } while ((subj = subj->parent_subject));
67548+ read_unlock(&gr_inode_lock);
67549+
67550+ /* this is purely an optimization since we're looking for an object
67551+ for the directory we're doing a readdir on
67552+ if it's possible for any globbed object to match the entry we're
67553+ filling into the directory, then the object we find here will be
67554+ an anchor point with attached globbed objects
67555+ */
67556+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
67557+ if (obj->globbed == NULL)
67558+ return (obj->mode & GR_FIND) ? 1 : 0;
67559+
67560+ is_not_root = ((obj->filename[0] == '/') &&
67561+ (obj->filename[1] == '\0')) ? 0 : 1;
67562+ bufsize = PAGE_SIZE - namelen - is_not_root;
67563+
67564+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
67565+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
67566+ return 1;
67567+
67568+ preempt_disable();
67569+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67570+ bufsize);
67571+
67572+ bufsize = strlen(path);
67573+
67574+ /* if base is "/", don't append an additional slash */
67575+ if (is_not_root)
67576+ *(path + bufsize) = '/';
67577+ memcpy(path + bufsize + is_not_root, name, namelen);
67578+ *(path + bufsize + namelen + is_not_root) = '\0';
67579+
67580+ tmp = obj->globbed;
67581+ while (tmp) {
67582+ if (!glob_match(tmp->filename, path)) {
67583+ preempt_enable();
67584+ return (tmp->mode & GR_FIND) ? 1 : 0;
67585+ }
67586+ tmp = tmp->next;
67587+ }
67588+ preempt_enable();
67589+ return (obj->mode & GR_FIND) ? 1 : 0;
67590+}
67591+
67592+void gr_put_exec_file(struct task_struct *task)
67593+{
67594+ struct file *filp;
67595+
67596+ write_lock(&grsec_exec_file_lock);
67597+ filp = task->exec_file;
67598+ task->exec_file = NULL;
67599+ write_unlock(&grsec_exec_file_lock);
67600+
67601+ if (filp)
67602+ fput(filp);
67603+
67604+ return;
67605+}
67606+
67607+
67608+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
67609+EXPORT_SYMBOL(gr_acl_is_enabled);
67610+#endif
67611+EXPORT_SYMBOL(gr_set_kernel_label);
67612+#ifdef CONFIG_SECURITY
67613+EXPORT_SYMBOL(gr_check_user_change);
67614+EXPORT_SYMBOL(gr_check_group_change);
67615+#endif
67616+
67617diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
67618new file mode 100644
67619index 0000000..34fefda
67620--- /dev/null
67621+++ b/grsecurity/gracl_alloc.c
67622@@ -0,0 +1,105 @@
67623+#include <linux/kernel.h>
67624+#include <linux/mm.h>
67625+#include <linux/slab.h>
67626+#include <linux/vmalloc.h>
67627+#include <linux/gracl.h>
67628+#include <linux/grsecurity.h>
67629+
67630+static unsigned long alloc_stack_next = 1;
67631+static unsigned long alloc_stack_size = 1;
67632+static void **alloc_stack;
67633+
67634+static __inline__ int
67635+alloc_pop(void)
67636+{
67637+ if (alloc_stack_next == 1)
67638+ return 0;
67639+
67640+ kfree(alloc_stack[alloc_stack_next - 2]);
67641+
67642+ alloc_stack_next--;
67643+
67644+ return 1;
67645+}
67646+
67647+static __inline__ int
67648+alloc_push(void *buf)
67649+{
67650+ if (alloc_stack_next >= alloc_stack_size)
67651+ return 1;
67652+
67653+ alloc_stack[alloc_stack_next - 1] = buf;
67654+
67655+ alloc_stack_next++;
67656+
67657+ return 0;
67658+}
67659+
67660+void *
67661+acl_alloc(unsigned long len)
67662+{
67663+ void *ret = NULL;
67664+
67665+ if (!len || len > PAGE_SIZE)
67666+ goto out;
67667+
67668+ ret = kmalloc(len, GFP_KERNEL);
67669+
67670+ if (ret) {
67671+ if (alloc_push(ret)) {
67672+ kfree(ret);
67673+ ret = NULL;
67674+ }
67675+ }
67676+
67677+out:
67678+ return ret;
67679+}
67680+
67681+void *
67682+acl_alloc_num(unsigned long num, unsigned long len)
67683+{
67684+ if (!len || (num > (PAGE_SIZE / len)))
67685+ return NULL;
67686+
67687+ return acl_alloc(num * len);
67688+}
67689+
67690+void
67691+acl_free_all(void)
67692+{
67693+ if (gr_acl_is_enabled() || !alloc_stack)
67694+ return;
67695+
67696+ while (alloc_pop()) ;
67697+
67698+ if (alloc_stack) {
67699+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
67700+ kfree(alloc_stack);
67701+ else
67702+ vfree(alloc_stack);
67703+ }
67704+
67705+ alloc_stack = NULL;
67706+ alloc_stack_size = 1;
67707+ alloc_stack_next = 1;
67708+
67709+ return;
67710+}
67711+
67712+int
67713+acl_alloc_stack_init(unsigned long size)
67714+{
67715+ if ((size * sizeof (void *)) <= PAGE_SIZE)
67716+ alloc_stack =
67717+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
67718+ else
67719+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
67720+
67721+ alloc_stack_size = size;
67722+
67723+ if (!alloc_stack)
67724+ return 0;
67725+ else
67726+ return 1;
67727+}
67728diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
67729new file mode 100644
67730index 0000000..bdd51ea
67731--- /dev/null
67732+++ b/grsecurity/gracl_cap.c
67733@@ -0,0 +1,110 @@
67734+#include <linux/kernel.h>
67735+#include <linux/module.h>
67736+#include <linux/sched.h>
67737+#include <linux/gracl.h>
67738+#include <linux/grsecurity.h>
67739+#include <linux/grinternal.h>
67740+
67741+extern const char *captab_log[];
67742+extern int captab_log_entries;
67743+
67744+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
67745+{
67746+ struct acl_subject_label *curracl;
67747+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
67748+ kernel_cap_t cap_audit = __cap_empty_set;
67749+
67750+ if (!gr_acl_is_enabled())
67751+ return 1;
67752+
67753+ curracl = task->acl;
67754+
67755+ cap_drop = curracl->cap_lower;
67756+ cap_mask = curracl->cap_mask;
67757+ cap_audit = curracl->cap_invert_audit;
67758+
67759+ while ((curracl = curracl->parent_subject)) {
67760+ /* if the cap isn't specified in the current computed mask but is specified in the
67761+ current level subject, and is lowered in the current level subject, then add
67762+ it to the set of dropped capabilities
67763+ otherwise, add the current level subject's mask to the current computed mask
67764+ */
67765+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
67766+ cap_raise(cap_mask, cap);
67767+ if (cap_raised(curracl->cap_lower, cap))
67768+ cap_raise(cap_drop, cap);
67769+ if (cap_raised(curracl->cap_invert_audit, cap))
67770+ cap_raise(cap_audit, cap);
67771+ }
67772+ }
67773+
67774+ if (!cap_raised(cap_drop, cap)) {
67775+ if (cap_raised(cap_audit, cap))
67776+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
67777+ return 1;
67778+ }
67779+
67780+ curracl = task->acl;
67781+
67782+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
67783+ && cap_raised(cred->cap_effective, cap)) {
67784+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67785+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
67786+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
67787+ gr_to_filename(task->exec_file->f_path.dentry,
67788+ task->exec_file->f_path.mnt) : curracl->filename,
67789+ curracl->filename, 0UL,
67790+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
67791+ return 1;
67792+ }
67793+
67794+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
67795+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
67796+
67797+ return 0;
67798+}
67799+
67800+int
67801+gr_acl_is_capable(const int cap)
67802+{
67803+ return gr_task_acl_is_capable(current, current_cred(), cap);
67804+}
67805+
67806+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
67807+{
67808+ struct acl_subject_label *curracl;
67809+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
67810+
67811+ if (!gr_acl_is_enabled())
67812+ return 1;
67813+
67814+ curracl = task->acl;
67815+
67816+ cap_drop = curracl->cap_lower;
67817+ cap_mask = curracl->cap_mask;
67818+
67819+ while ((curracl = curracl->parent_subject)) {
67820+ /* if the cap isn't specified in the current computed mask but is specified in the
67821+ current level subject, and is lowered in the current level subject, then add
67822+ it to the set of dropped capabilities
67823+ otherwise, add the current level subject's mask to the current computed mask
67824+ */
67825+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
67826+ cap_raise(cap_mask, cap);
67827+ if (cap_raised(curracl->cap_lower, cap))
67828+ cap_raise(cap_drop, cap);
67829+ }
67830+ }
67831+
67832+ if (!cap_raised(cap_drop, cap))
67833+ return 1;
67834+
67835+ return 0;
67836+}
67837+
67838+int
67839+gr_acl_is_capable_nolog(const int cap)
67840+{
67841+ return gr_task_acl_is_capable_nolog(current, cap);
67842+}
67843+
67844diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
67845new file mode 100644
67846index 0000000..a43dd06
67847--- /dev/null
67848+++ b/grsecurity/gracl_compat.c
67849@@ -0,0 +1,269 @@
67850+#include <linux/kernel.h>
67851+#include <linux/gracl.h>
67852+#include <linux/compat.h>
67853+#include <linux/gracl_compat.h>
67854+
67855+#include <asm/uaccess.h>
67856+
67857+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
67858+{
67859+ struct gr_arg_wrapper_compat uwrapcompat;
67860+
67861+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
67862+ return -EFAULT;
67863+
67864+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
67865+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
67866+ return -EINVAL;
67867+
67868+ uwrap->arg = compat_ptr(uwrapcompat.arg);
67869+ uwrap->version = uwrapcompat.version;
67870+ uwrap->size = sizeof(struct gr_arg);
67871+
67872+ return 0;
67873+}
67874+
67875+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
67876+{
67877+ struct gr_arg_compat argcompat;
67878+
67879+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
67880+ return -EFAULT;
67881+
67882+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
67883+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
67884+ arg->role_db.num_roles = argcompat.role_db.num_roles;
67885+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
67886+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
67887+ arg->role_db.num_objects = argcompat.role_db.num_objects;
67888+
67889+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
67890+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
67891+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
67892+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
67893+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
67894+ arg->segv_device = argcompat.segv_device;
67895+ arg->segv_inode = argcompat.segv_inode;
67896+ arg->segv_uid = argcompat.segv_uid;
67897+ arg->num_sprole_pws = argcompat.num_sprole_pws;
67898+ arg->mode = argcompat.mode;
67899+
67900+ return 0;
67901+}
67902+
67903+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
67904+{
67905+ struct acl_object_label_compat objcompat;
67906+
67907+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
67908+ return -EFAULT;
67909+
67910+ obj->filename = compat_ptr(objcompat.filename);
67911+ obj->inode = objcompat.inode;
67912+ obj->device = objcompat.device;
67913+ obj->mode = objcompat.mode;
67914+
67915+ obj->nested = compat_ptr(objcompat.nested);
67916+ obj->globbed = compat_ptr(objcompat.globbed);
67917+
67918+ obj->prev = compat_ptr(objcompat.prev);
67919+ obj->next = compat_ptr(objcompat.next);
67920+
67921+ return 0;
67922+}
67923+
67924+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
67925+{
67926+ unsigned int i;
67927+ struct acl_subject_label_compat subjcompat;
67928+
67929+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
67930+ return -EFAULT;
67931+
67932+ subj->filename = compat_ptr(subjcompat.filename);
67933+ subj->inode = subjcompat.inode;
67934+ subj->device = subjcompat.device;
67935+ subj->mode = subjcompat.mode;
67936+ subj->cap_mask = subjcompat.cap_mask;
67937+ subj->cap_lower = subjcompat.cap_lower;
67938+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
67939+
67940+ for (i = 0; i < GR_NLIMITS; i++) {
67941+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
67942+ subj->res[i].rlim_cur = RLIM_INFINITY;
67943+ else
67944+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
67945+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
67946+ subj->res[i].rlim_max = RLIM_INFINITY;
67947+ else
67948+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
67949+ }
67950+ subj->resmask = subjcompat.resmask;
67951+
67952+ subj->user_trans_type = subjcompat.user_trans_type;
67953+ subj->group_trans_type = subjcompat.group_trans_type;
67954+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
67955+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
67956+ subj->user_trans_num = subjcompat.user_trans_num;
67957+ subj->group_trans_num = subjcompat.group_trans_num;
67958+
67959+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
67960+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
67961+ subj->ip_type = subjcompat.ip_type;
67962+ subj->ips = compat_ptr(subjcompat.ips);
67963+ subj->ip_num = subjcompat.ip_num;
67964+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
67965+
67966+ subj->crashes = subjcompat.crashes;
67967+ subj->expires = subjcompat.expires;
67968+
67969+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
67970+ subj->hash = compat_ptr(subjcompat.hash);
67971+ subj->prev = compat_ptr(subjcompat.prev);
67972+ subj->next = compat_ptr(subjcompat.next);
67973+
67974+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
67975+ subj->obj_hash_size = subjcompat.obj_hash_size;
67976+ subj->pax_flags = subjcompat.pax_flags;
67977+
67978+ return 0;
67979+}
67980+
67981+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
67982+{
67983+ struct acl_role_label_compat rolecompat;
67984+
67985+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
67986+ return -EFAULT;
67987+
67988+ role->rolename = compat_ptr(rolecompat.rolename);
67989+ role->uidgid = rolecompat.uidgid;
67990+ role->roletype = rolecompat.roletype;
67991+
67992+ role->auth_attempts = rolecompat.auth_attempts;
67993+ role->expires = rolecompat.expires;
67994+
67995+ role->root_label = compat_ptr(rolecompat.root_label);
67996+ role->hash = compat_ptr(rolecompat.hash);
67997+
67998+ role->prev = compat_ptr(rolecompat.prev);
67999+ role->next = compat_ptr(rolecompat.next);
68000+
68001+ role->transitions = compat_ptr(rolecompat.transitions);
68002+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68003+ role->domain_children = compat_ptr(rolecompat.domain_children);
68004+ role->domain_child_num = rolecompat.domain_child_num;
68005+
68006+ role->umask = rolecompat.umask;
68007+
68008+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
68009+ role->subj_hash_size = rolecompat.subj_hash_size;
68010+
68011+ return 0;
68012+}
68013+
68014+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68015+{
68016+ struct role_allowed_ip_compat roleip_compat;
68017+
68018+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68019+ return -EFAULT;
68020+
68021+ roleip->addr = roleip_compat.addr;
68022+ roleip->netmask = roleip_compat.netmask;
68023+
68024+ roleip->prev = compat_ptr(roleip_compat.prev);
68025+ roleip->next = compat_ptr(roleip_compat.next);
68026+
68027+ return 0;
68028+}
68029+
68030+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68031+{
68032+ struct role_transition_compat trans_compat;
68033+
68034+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68035+ return -EFAULT;
68036+
68037+ trans->rolename = compat_ptr(trans_compat.rolename);
68038+
68039+ trans->prev = compat_ptr(trans_compat.prev);
68040+ trans->next = compat_ptr(trans_compat.next);
68041+
68042+ return 0;
68043+
68044+}
68045+
68046+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68047+{
68048+ struct gr_hash_struct_compat hash_compat;
68049+
68050+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68051+ return -EFAULT;
68052+
68053+ hash->table = compat_ptr(hash_compat.table);
68054+ hash->nametable = compat_ptr(hash_compat.nametable);
68055+ hash->first = compat_ptr(hash_compat.first);
68056+
68057+ hash->table_size = hash_compat.table_size;
68058+ hash->used_size = hash_compat.used_size;
68059+
68060+ hash->type = hash_compat.type;
68061+
68062+ return 0;
68063+}
68064+
68065+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68066+{
68067+ compat_uptr_t ptrcompat;
68068+
68069+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68070+ return -EFAULT;
68071+
68072+ *(void **)ptr = compat_ptr(ptrcompat);
68073+
68074+ return 0;
68075+}
68076+
68077+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68078+{
68079+ struct acl_ip_label_compat ip_compat;
68080+
68081+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68082+ return -EFAULT;
68083+
68084+ ip->iface = compat_ptr(ip_compat.iface);
68085+ ip->addr = ip_compat.addr;
68086+ ip->netmask = ip_compat.netmask;
68087+ ip->low = ip_compat.low;
68088+ ip->high = ip_compat.high;
68089+ ip->mode = ip_compat.mode;
68090+ ip->type = ip_compat.type;
68091+
68092+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68093+
68094+ ip->prev = compat_ptr(ip_compat.prev);
68095+ ip->next = compat_ptr(ip_compat.next);
68096+
68097+ return 0;
68098+}
68099+
68100+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68101+{
68102+ struct sprole_pw_compat pw_compat;
68103+
68104+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68105+ return -EFAULT;
68106+
68107+ pw->rolename = compat_ptr(pw_compat.rolename);
68108+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68109+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68110+
68111+ return 0;
68112+}
68113+
68114+size_t get_gr_arg_wrapper_size_compat(void)
68115+{
68116+ return sizeof(struct gr_arg_wrapper_compat);
68117+}
68118+
68119diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68120new file mode 100644
68121index 0000000..a340c17
68122--- /dev/null
68123+++ b/grsecurity/gracl_fs.c
68124@@ -0,0 +1,431 @@
68125+#include <linux/kernel.h>
68126+#include <linux/sched.h>
68127+#include <linux/types.h>
68128+#include <linux/fs.h>
68129+#include <linux/file.h>
68130+#include <linux/stat.h>
68131+#include <linux/grsecurity.h>
68132+#include <linux/grinternal.h>
68133+#include <linux/gracl.h>
68134+
68135+umode_t
68136+gr_acl_umask(void)
68137+{
68138+ if (unlikely(!gr_acl_is_enabled()))
68139+ return 0;
68140+
68141+ return current->role->umask;
68142+}
68143+
68144+__u32
68145+gr_acl_handle_hidden_file(const struct dentry * dentry,
68146+ const struct vfsmount * mnt)
68147+{
68148+ __u32 mode;
68149+
68150+ if (unlikely(!dentry->d_inode))
68151+ return GR_FIND;
68152+
68153+ mode =
68154+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68155+
68156+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68157+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68158+ return mode;
68159+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68160+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68161+ return 0;
68162+ } else if (unlikely(!(mode & GR_FIND)))
68163+ return 0;
68164+
68165+ return GR_FIND;
68166+}
68167+
68168+__u32
68169+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68170+ int acc_mode)
68171+{
68172+ __u32 reqmode = GR_FIND;
68173+ __u32 mode;
68174+
68175+ if (unlikely(!dentry->d_inode))
68176+ return reqmode;
68177+
68178+ if (acc_mode & MAY_APPEND)
68179+ reqmode |= GR_APPEND;
68180+ else if (acc_mode & MAY_WRITE)
68181+ reqmode |= GR_WRITE;
68182+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68183+ reqmode |= GR_READ;
68184+
68185+ mode =
68186+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68187+ mnt);
68188+
68189+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68190+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68191+ reqmode & GR_READ ? " reading" : "",
68192+ reqmode & GR_WRITE ? " writing" : reqmode &
68193+ GR_APPEND ? " appending" : "");
68194+ return reqmode;
68195+ } else
68196+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68197+ {
68198+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68199+ reqmode & GR_READ ? " reading" : "",
68200+ reqmode & GR_WRITE ? " writing" : reqmode &
68201+ GR_APPEND ? " appending" : "");
68202+ return 0;
68203+ } else if (unlikely((mode & reqmode) != reqmode))
68204+ return 0;
68205+
68206+ return reqmode;
68207+}
68208+
68209+__u32
68210+gr_acl_handle_creat(const struct dentry * dentry,
68211+ const struct dentry * p_dentry,
68212+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68213+ const int imode)
68214+{
68215+ __u32 reqmode = GR_WRITE | GR_CREATE;
68216+ __u32 mode;
68217+
68218+ if (acc_mode & MAY_APPEND)
68219+ reqmode |= GR_APPEND;
68220+ // if a directory was required or the directory already exists, then
68221+ // don't count this open as a read
68222+ if ((acc_mode & MAY_READ) &&
68223+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68224+ reqmode |= GR_READ;
68225+ if ((open_flags & O_CREAT) &&
68226+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68227+ reqmode |= GR_SETID;
68228+
68229+ mode =
68230+ gr_check_create(dentry, p_dentry, p_mnt,
68231+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68232+
68233+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68234+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68235+ reqmode & GR_READ ? " reading" : "",
68236+ reqmode & GR_WRITE ? " writing" : reqmode &
68237+ GR_APPEND ? " appending" : "");
68238+ return reqmode;
68239+ } else
68240+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68241+ {
68242+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68243+ reqmode & GR_READ ? " reading" : "",
68244+ reqmode & GR_WRITE ? " writing" : reqmode &
68245+ GR_APPEND ? " appending" : "");
68246+ return 0;
68247+ } else if (unlikely((mode & reqmode) != reqmode))
68248+ return 0;
68249+
68250+ return reqmode;
68251+}
68252+
68253+__u32
68254+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68255+ const int fmode)
68256+{
68257+ __u32 mode, reqmode = GR_FIND;
68258+
68259+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68260+ reqmode |= GR_EXEC;
68261+ if (fmode & S_IWOTH)
68262+ reqmode |= GR_WRITE;
68263+ if (fmode & S_IROTH)
68264+ reqmode |= GR_READ;
68265+
68266+ mode =
68267+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68268+ mnt);
68269+
68270+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68271+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68272+ reqmode & GR_READ ? " reading" : "",
68273+ reqmode & GR_WRITE ? " writing" : "",
68274+ reqmode & GR_EXEC ? " executing" : "");
68275+ return reqmode;
68276+ } else
68277+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68278+ {
68279+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68280+ reqmode & GR_READ ? " reading" : "",
68281+ reqmode & GR_WRITE ? " writing" : "",
68282+ reqmode & GR_EXEC ? " executing" : "");
68283+ return 0;
68284+ } else if (unlikely((mode & reqmode) != reqmode))
68285+ return 0;
68286+
68287+ return reqmode;
68288+}
68289+
68290+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68291+{
68292+ __u32 mode;
68293+
68294+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68295+
68296+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68297+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68298+ return mode;
68299+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68300+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68301+ return 0;
68302+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68303+ return 0;
68304+
68305+ return (reqmode);
68306+}
68307+
68308+__u32
68309+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68310+{
68311+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68312+}
68313+
68314+__u32
68315+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68316+{
68317+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68318+}
68319+
68320+__u32
68321+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68322+{
68323+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68324+}
68325+
68326+__u32
68327+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68328+{
68329+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68330+}
68331+
68332+__u32
68333+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68334+ umode_t *modeptr)
68335+{
68336+ umode_t mode;
68337+
68338+ *modeptr &= ~gr_acl_umask();
68339+ mode = *modeptr;
68340+
68341+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68342+ return 1;
68343+
68344+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68345+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68346+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68347+ GR_CHMOD_ACL_MSG);
68348+ } else {
68349+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68350+ }
68351+}
68352+
68353+__u32
68354+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68355+{
68356+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68357+}
68358+
68359+__u32
68360+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68361+{
68362+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68363+}
68364+
68365+__u32
68366+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68367+{
68368+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68369+}
68370+
68371+__u32
68372+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68373+{
68374+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68375+ GR_UNIXCONNECT_ACL_MSG);
68376+}
68377+
68378+/* hardlinks require at minimum create and link permission,
68379+ any additional privilege required is based on the
68380+ privilege of the file being linked to
68381+*/
68382+__u32
68383+gr_acl_handle_link(const struct dentry * new_dentry,
68384+ const struct dentry * parent_dentry,
68385+ const struct vfsmount * parent_mnt,
68386+ const struct dentry * old_dentry,
68387+ const struct vfsmount * old_mnt, const struct filename *to)
68388+{
68389+ __u32 mode;
68390+ __u32 needmode = GR_CREATE | GR_LINK;
68391+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68392+
68393+ mode =
68394+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68395+ old_mnt);
68396+
68397+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68398+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68399+ return mode;
68400+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68401+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68402+ return 0;
68403+ } else if (unlikely((mode & needmode) != needmode))
68404+ return 0;
68405+
68406+ return 1;
68407+}
68408+
68409+__u32
68410+gr_acl_handle_symlink(const struct dentry * new_dentry,
68411+ const struct dentry * parent_dentry,
68412+ const struct vfsmount * parent_mnt, const struct filename *from)
68413+{
68414+ __u32 needmode = GR_WRITE | GR_CREATE;
68415+ __u32 mode;
68416+
68417+ mode =
68418+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
68419+ GR_CREATE | GR_AUDIT_CREATE |
68420+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68421+
68422+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68423+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68424+ return mode;
68425+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68426+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68427+ return 0;
68428+ } else if (unlikely((mode & needmode) != needmode))
68429+ return 0;
68430+
68431+ return (GR_WRITE | GR_CREATE);
68432+}
68433+
68434+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)
68435+{
68436+ __u32 mode;
68437+
68438+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68439+
68440+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68441+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68442+ return mode;
68443+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68444+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68445+ return 0;
68446+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
68447+ return 0;
68448+
68449+ return (reqmode);
68450+}
68451+
68452+__u32
68453+gr_acl_handle_mknod(const struct dentry * new_dentry,
68454+ const struct dentry * parent_dentry,
68455+ const struct vfsmount * parent_mnt,
68456+ const int mode)
68457+{
68458+ __u32 reqmode = GR_WRITE | GR_CREATE;
68459+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68460+ reqmode |= GR_SETID;
68461+
68462+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68463+ reqmode, GR_MKNOD_ACL_MSG);
68464+}
68465+
68466+__u32
68467+gr_acl_handle_mkdir(const struct dentry *new_dentry,
68468+ const struct dentry *parent_dentry,
68469+ const struct vfsmount *parent_mnt)
68470+{
68471+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68472+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68473+}
68474+
68475+#define RENAME_CHECK_SUCCESS(old, new) \
68476+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68477+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68478+
68479+int
68480+gr_acl_handle_rename(struct dentry *new_dentry,
68481+ struct dentry *parent_dentry,
68482+ const struct vfsmount *parent_mnt,
68483+ struct dentry *old_dentry,
68484+ struct inode *old_parent_inode,
68485+ struct vfsmount *old_mnt, const struct filename *newname)
68486+{
68487+ __u32 comp1, comp2;
68488+ int error = 0;
68489+
68490+ if (unlikely(!gr_acl_is_enabled()))
68491+ return 0;
68492+
68493+ if (!new_dentry->d_inode) {
68494+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
68495+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
68496+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
68497+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
68498+ GR_DELETE | GR_AUDIT_DELETE |
68499+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68500+ GR_SUPPRESS, old_mnt);
68501+ } else {
68502+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
68503+ GR_CREATE | GR_DELETE |
68504+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
68505+ GR_AUDIT_READ | GR_AUDIT_WRITE |
68506+ GR_SUPPRESS, parent_mnt);
68507+ comp2 =
68508+ gr_search_file(old_dentry,
68509+ GR_READ | GR_WRITE | GR_AUDIT_READ |
68510+ GR_DELETE | GR_AUDIT_DELETE |
68511+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
68512+ }
68513+
68514+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
68515+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
68516+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68517+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
68518+ && !(comp2 & GR_SUPPRESS)) {
68519+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68520+ error = -EACCES;
68521+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
68522+ error = -EACCES;
68523+
68524+ return error;
68525+}
68526+
68527+void
68528+gr_acl_handle_exit(void)
68529+{
68530+ u16 id;
68531+ char *rolename;
68532+
68533+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
68534+ !(current->role->roletype & GR_ROLE_PERSIST))) {
68535+ id = current->acl_role_id;
68536+ rolename = current->role->rolename;
68537+ gr_set_acls(1);
68538+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
68539+ }
68540+
68541+ gr_put_exec_file(current);
68542+ return;
68543+}
68544+
68545+int
68546+gr_acl_handle_procpidmem(const struct task_struct *task)
68547+{
68548+ if (unlikely(!gr_acl_is_enabled()))
68549+ return 0;
68550+
68551+ if (task != current && task->acl->mode & GR_PROTPROCFD)
68552+ return -EACCES;
68553+
68554+ return 0;
68555+}
68556diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
68557new file mode 100644
68558index 0000000..8132048
68559--- /dev/null
68560+++ b/grsecurity/gracl_ip.c
68561@@ -0,0 +1,387 @@
68562+#include <linux/kernel.h>
68563+#include <asm/uaccess.h>
68564+#include <asm/errno.h>
68565+#include <net/sock.h>
68566+#include <linux/file.h>
68567+#include <linux/fs.h>
68568+#include <linux/net.h>
68569+#include <linux/in.h>
68570+#include <linux/skbuff.h>
68571+#include <linux/ip.h>
68572+#include <linux/udp.h>
68573+#include <linux/types.h>
68574+#include <linux/sched.h>
68575+#include <linux/netdevice.h>
68576+#include <linux/inetdevice.h>
68577+#include <linux/gracl.h>
68578+#include <linux/grsecurity.h>
68579+#include <linux/grinternal.h>
68580+
68581+#define GR_BIND 0x01
68582+#define GR_CONNECT 0x02
68583+#define GR_INVERT 0x04
68584+#define GR_BINDOVERRIDE 0x08
68585+#define GR_CONNECTOVERRIDE 0x10
68586+#define GR_SOCK_FAMILY 0x20
68587+
68588+static const char * gr_protocols[IPPROTO_MAX] = {
68589+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
68590+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
68591+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
68592+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
68593+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
68594+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
68595+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
68596+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
68597+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
68598+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
68599+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
68600+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
68601+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
68602+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
68603+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
68604+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
68605+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
68606+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
68607+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
68608+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
68609+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
68610+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
68611+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
68612+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
68613+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
68614+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
68615+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
68616+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
68617+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
68618+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
68619+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
68620+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
68621+ };
68622+
68623+static const char * gr_socktypes[SOCK_MAX] = {
68624+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
68625+ "unknown:7", "unknown:8", "unknown:9", "packet"
68626+ };
68627+
68628+static const char * gr_sockfamilies[AF_MAX+1] = {
68629+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
68630+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
68631+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
68632+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
68633+ };
68634+
68635+const char *
68636+gr_proto_to_name(unsigned char proto)
68637+{
68638+ return gr_protocols[proto];
68639+}
68640+
68641+const char *
68642+gr_socktype_to_name(unsigned char type)
68643+{
68644+ return gr_socktypes[type];
68645+}
68646+
68647+const char *
68648+gr_sockfamily_to_name(unsigned char family)
68649+{
68650+ return gr_sockfamilies[family];
68651+}
68652+
68653+int
68654+gr_search_socket(const int domain, const int type, const int protocol)
68655+{
68656+ struct acl_subject_label *curr;
68657+ const struct cred *cred = current_cred();
68658+
68659+ if (unlikely(!gr_acl_is_enabled()))
68660+ goto exit;
68661+
68662+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
68663+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
68664+ goto exit; // let the kernel handle it
68665+
68666+ curr = current->acl;
68667+
68668+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
68669+ /* the family is allowed, if this is PF_INET allow it only if
68670+ the extra sock type/protocol checks pass */
68671+ if (domain == PF_INET)
68672+ goto inet_check;
68673+ goto exit;
68674+ } else {
68675+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68676+ __u32 fakeip = 0;
68677+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68678+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68679+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68680+ gr_to_filename(current->exec_file->f_path.dentry,
68681+ current->exec_file->f_path.mnt) :
68682+ curr->filename, curr->filename,
68683+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
68684+ &current->signal->saved_ip);
68685+ goto exit;
68686+ }
68687+ goto exit_fail;
68688+ }
68689+
68690+inet_check:
68691+ /* the rest of this checking is for IPv4 only */
68692+ if (!curr->ips)
68693+ goto exit;
68694+
68695+ if ((curr->ip_type & (1U << type)) &&
68696+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
68697+ goto exit;
68698+
68699+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68700+ /* we don't place acls on raw sockets , and sometimes
68701+ dgram/ip sockets are opened for ioctl and not
68702+ bind/connect, so we'll fake a bind learn log */
68703+ if (type == SOCK_RAW || type == SOCK_PACKET) {
68704+ __u32 fakeip = 0;
68705+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68706+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68707+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68708+ gr_to_filename(current->exec_file->f_path.dentry,
68709+ current->exec_file->f_path.mnt) :
68710+ curr->filename, curr->filename,
68711+ &fakeip, 0, type,
68712+ protocol, GR_CONNECT, &current->signal->saved_ip);
68713+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
68714+ __u32 fakeip = 0;
68715+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68716+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68717+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68718+ gr_to_filename(current->exec_file->f_path.dentry,
68719+ current->exec_file->f_path.mnt) :
68720+ curr->filename, curr->filename,
68721+ &fakeip, 0, type,
68722+ protocol, GR_BIND, &current->signal->saved_ip);
68723+ }
68724+ /* we'll log when they use connect or bind */
68725+ goto exit;
68726+ }
68727+
68728+exit_fail:
68729+ if (domain == PF_INET)
68730+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
68731+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
68732+ else
68733+#ifndef CONFIG_IPV6
68734+ if (domain != PF_INET6)
68735+#endif
68736+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
68737+ gr_socktype_to_name(type), protocol);
68738+
68739+ return 0;
68740+exit:
68741+ return 1;
68742+}
68743+
68744+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)
68745+{
68746+ if ((ip->mode & mode) &&
68747+ (ip_port >= ip->low) &&
68748+ (ip_port <= ip->high) &&
68749+ ((ntohl(ip_addr) & our_netmask) ==
68750+ (ntohl(our_addr) & our_netmask))
68751+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
68752+ && (ip->type & (1U << type))) {
68753+ if (ip->mode & GR_INVERT)
68754+ return 2; // specifically denied
68755+ else
68756+ return 1; // allowed
68757+ }
68758+
68759+ return 0; // not specifically allowed, may continue parsing
68760+}
68761+
68762+static int
68763+gr_search_connectbind(const int full_mode, struct sock *sk,
68764+ struct sockaddr_in *addr, const int type)
68765+{
68766+ char iface[IFNAMSIZ] = {0};
68767+ struct acl_subject_label *curr;
68768+ struct acl_ip_label *ip;
68769+ struct inet_sock *isk;
68770+ struct net_device *dev;
68771+ struct in_device *idev;
68772+ unsigned long i;
68773+ int ret;
68774+ int mode = full_mode & (GR_BIND | GR_CONNECT);
68775+ __u32 ip_addr = 0;
68776+ __u32 our_addr;
68777+ __u32 our_netmask;
68778+ char *p;
68779+ __u16 ip_port = 0;
68780+ const struct cred *cred = current_cred();
68781+
68782+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
68783+ return 0;
68784+
68785+ curr = current->acl;
68786+ isk = inet_sk(sk);
68787+
68788+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
68789+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
68790+ addr->sin_addr.s_addr = curr->inaddr_any_override;
68791+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
68792+ struct sockaddr_in saddr;
68793+ int err;
68794+
68795+ saddr.sin_family = AF_INET;
68796+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
68797+ saddr.sin_port = isk->inet_sport;
68798+
68799+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
68800+ if (err)
68801+ return err;
68802+
68803+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
68804+ if (err)
68805+ return err;
68806+ }
68807+
68808+ if (!curr->ips)
68809+ return 0;
68810+
68811+ ip_addr = addr->sin_addr.s_addr;
68812+ ip_port = ntohs(addr->sin_port);
68813+
68814+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
68815+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
68816+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
68817+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
68818+ gr_to_filename(current->exec_file->f_path.dentry,
68819+ current->exec_file->f_path.mnt) :
68820+ curr->filename, curr->filename,
68821+ &ip_addr, ip_port, type,
68822+ sk->sk_protocol, mode, &current->signal->saved_ip);
68823+ return 0;
68824+ }
68825+
68826+ for (i = 0; i < curr->ip_num; i++) {
68827+ ip = *(curr->ips + i);
68828+ if (ip->iface != NULL) {
68829+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
68830+ p = strchr(iface, ':');
68831+ if (p != NULL)
68832+ *p = '\0';
68833+ dev = dev_get_by_name(sock_net(sk), iface);
68834+ if (dev == NULL)
68835+ continue;
68836+ idev = in_dev_get(dev);
68837+ if (idev == NULL) {
68838+ dev_put(dev);
68839+ continue;
68840+ }
68841+ rcu_read_lock();
68842+ for_ifa(idev) {
68843+ if (!strcmp(ip->iface, ifa->ifa_label)) {
68844+ our_addr = ifa->ifa_address;
68845+ our_netmask = 0xffffffff;
68846+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
68847+ if (ret == 1) {
68848+ rcu_read_unlock();
68849+ in_dev_put(idev);
68850+ dev_put(dev);
68851+ return 0;
68852+ } else if (ret == 2) {
68853+ rcu_read_unlock();
68854+ in_dev_put(idev);
68855+ dev_put(dev);
68856+ goto denied;
68857+ }
68858+ }
68859+ } endfor_ifa(idev);
68860+ rcu_read_unlock();
68861+ in_dev_put(idev);
68862+ dev_put(dev);
68863+ } else {
68864+ our_addr = ip->addr;
68865+ our_netmask = ip->netmask;
68866+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
68867+ if (ret == 1)
68868+ return 0;
68869+ else if (ret == 2)
68870+ goto denied;
68871+ }
68872+ }
68873+
68874+denied:
68875+ if (mode == GR_BIND)
68876+ 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));
68877+ else if (mode == GR_CONNECT)
68878+ 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));
68879+
68880+ return -EACCES;
68881+}
68882+
68883+int
68884+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
68885+{
68886+ /* always allow disconnection of dgram sockets with connect */
68887+ if (addr->sin_family == AF_UNSPEC)
68888+ return 0;
68889+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
68890+}
68891+
68892+int
68893+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
68894+{
68895+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
68896+}
68897+
68898+int gr_search_listen(struct socket *sock)
68899+{
68900+ struct sock *sk = sock->sk;
68901+ struct sockaddr_in addr;
68902+
68903+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
68904+ addr.sin_port = inet_sk(sk)->inet_sport;
68905+
68906+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
68907+}
68908+
68909+int gr_search_accept(struct socket *sock)
68910+{
68911+ struct sock *sk = sock->sk;
68912+ struct sockaddr_in addr;
68913+
68914+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
68915+ addr.sin_port = inet_sk(sk)->inet_sport;
68916+
68917+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
68918+}
68919+
68920+int
68921+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
68922+{
68923+ if (addr)
68924+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
68925+ else {
68926+ struct sockaddr_in sin;
68927+ const struct inet_sock *inet = inet_sk(sk);
68928+
68929+ sin.sin_addr.s_addr = inet->inet_daddr;
68930+ sin.sin_port = inet->inet_dport;
68931+
68932+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
68933+ }
68934+}
68935+
68936+int
68937+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
68938+{
68939+ struct sockaddr_in sin;
68940+
68941+ if (unlikely(skb->len < sizeof (struct udphdr)))
68942+ return 0; // skip this packet
68943+
68944+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
68945+ sin.sin_port = udp_hdr(skb)->source;
68946+
68947+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
68948+}
68949diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
68950new file mode 100644
68951index 0000000..25f54ef
68952--- /dev/null
68953+++ b/grsecurity/gracl_learn.c
68954@@ -0,0 +1,207 @@
68955+#include <linux/kernel.h>
68956+#include <linux/mm.h>
68957+#include <linux/sched.h>
68958+#include <linux/poll.h>
68959+#include <linux/string.h>
68960+#include <linux/file.h>
68961+#include <linux/types.h>
68962+#include <linux/vmalloc.h>
68963+#include <linux/grinternal.h>
68964+
68965+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
68966+ size_t count, loff_t *ppos);
68967+extern int gr_acl_is_enabled(void);
68968+
68969+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
68970+static int gr_learn_attached;
68971+
68972+/* use a 512k buffer */
68973+#define LEARN_BUFFER_SIZE (512 * 1024)
68974+
68975+static DEFINE_SPINLOCK(gr_learn_lock);
68976+static DEFINE_MUTEX(gr_learn_user_mutex);
68977+
68978+/* we need to maintain two buffers, so that the kernel context of grlearn
68979+ uses a semaphore around the userspace copying, and the other kernel contexts
68980+ use a spinlock when copying into the buffer, since they cannot sleep
68981+*/
68982+static char *learn_buffer;
68983+static char *learn_buffer_user;
68984+static int learn_buffer_len;
68985+static int learn_buffer_user_len;
68986+
68987+static ssize_t
68988+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
68989+{
68990+ DECLARE_WAITQUEUE(wait, current);
68991+ ssize_t retval = 0;
68992+
68993+ add_wait_queue(&learn_wait, &wait);
68994+ set_current_state(TASK_INTERRUPTIBLE);
68995+ do {
68996+ mutex_lock(&gr_learn_user_mutex);
68997+ spin_lock(&gr_learn_lock);
68998+ if (learn_buffer_len)
68999+ break;
69000+ spin_unlock(&gr_learn_lock);
69001+ mutex_unlock(&gr_learn_user_mutex);
69002+ if (file->f_flags & O_NONBLOCK) {
69003+ retval = -EAGAIN;
69004+ goto out;
69005+ }
69006+ if (signal_pending(current)) {
69007+ retval = -ERESTARTSYS;
69008+ goto out;
69009+ }
69010+
69011+ schedule();
69012+ } while (1);
69013+
69014+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69015+ learn_buffer_user_len = learn_buffer_len;
69016+ retval = learn_buffer_len;
69017+ learn_buffer_len = 0;
69018+
69019+ spin_unlock(&gr_learn_lock);
69020+
69021+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69022+ retval = -EFAULT;
69023+
69024+ mutex_unlock(&gr_learn_user_mutex);
69025+out:
69026+ set_current_state(TASK_RUNNING);
69027+ remove_wait_queue(&learn_wait, &wait);
69028+ return retval;
69029+}
69030+
69031+static unsigned int
69032+poll_learn(struct file * file, poll_table * wait)
69033+{
69034+ poll_wait(file, &learn_wait, wait);
69035+
69036+ if (learn_buffer_len)
69037+ return (POLLIN | POLLRDNORM);
69038+
69039+ return 0;
69040+}
69041+
69042+void
69043+gr_clear_learn_entries(void)
69044+{
69045+ char *tmp;
69046+
69047+ mutex_lock(&gr_learn_user_mutex);
69048+ spin_lock(&gr_learn_lock);
69049+ tmp = learn_buffer;
69050+ learn_buffer = NULL;
69051+ spin_unlock(&gr_learn_lock);
69052+ if (tmp)
69053+ vfree(tmp);
69054+ if (learn_buffer_user != NULL) {
69055+ vfree(learn_buffer_user);
69056+ learn_buffer_user = NULL;
69057+ }
69058+ learn_buffer_len = 0;
69059+ mutex_unlock(&gr_learn_user_mutex);
69060+
69061+ return;
69062+}
69063+
69064+void
69065+gr_add_learn_entry(const char *fmt, ...)
69066+{
69067+ va_list args;
69068+ unsigned int len;
69069+
69070+ if (!gr_learn_attached)
69071+ return;
69072+
69073+ spin_lock(&gr_learn_lock);
69074+
69075+ /* leave a gap at the end so we know when it's "full" but don't have to
69076+ compute the exact length of the string we're trying to append
69077+ */
69078+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69079+ spin_unlock(&gr_learn_lock);
69080+ wake_up_interruptible(&learn_wait);
69081+ return;
69082+ }
69083+ if (learn_buffer == NULL) {
69084+ spin_unlock(&gr_learn_lock);
69085+ return;
69086+ }
69087+
69088+ va_start(args, fmt);
69089+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69090+ va_end(args);
69091+
69092+ learn_buffer_len += len + 1;
69093+
69094+ spin_unlock(&gr_learn_lock);
69095+ wake_up_interruptible(&learn_wait);
69096+
69097+ return;
69098+}
69099+
69100+static int
69101+open_learn(struct inode *inode, struct file *file)
69102+{
69103+ if (file->f_mode & FMODE_READ && gr_learn_attached)
69104+ return -EBUSY;
69105+ if (file->f_mode & FMODE_READ) {
69106+ int retval = 0;
69107+ mutex_lock(&gr_learn_user_mutex);
69108+ if (learn_buffer == NULL)
69109+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69110+ if (learn_buffer_user == NULL)
69111+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69112+ if (learn_buffer == NULL) {
69113+ retval = -ENOMEM;
69114+ goto out_error;
69115+ }
69116+ if (learn_buffer_user == NULL) {
69117+ retval = -ENOMEM;
69118+ goto out_error;
69119+ }
69120+ learn_buffer_len = 0;
69121+ learn_buffer_user_len = 0;
69122+ gr_learn_attached = 1;
69123+out_error:
69124+ mutex_unlock(&gr_learn_user_mutex);
69125+ return retval;
69126+ }
69127+ return 0;
69128+}
69129+
69130+static int
69131+close_learn(struct inode *inode, struct file *file)
69132+{
69133+ if (file->f_mode & FMODE_READ) {
69134+ char *tmp = NULL;
69135+ mutex_lock(&gr_learn_user_mutex);
69136+ spin_lock(&gr_learn_lock);
69137+ tmp = learn_buffer;
69138+ learn_buffer = NULL;
69139+ spin_unlock(&gr_learn_lock);
69140+ if (tmp)
69141+ vfree(tmp);
69142+ if (learn_buffer_user != NULL) {
69143+ vfree(learn_buffer_user);
69144+ learn_buffer_user = NULL;
69145+ }
69146+ learn_buffer_len = 0;
69147+ learn_buffer_user_len = 0;
69148+ gr_learn_attached = 0;
69149+ mutex_unlock(&gr_learn_user_mutex);
69150+ }
69151+
69152+ return 0;
69153+}
69154+
69155+const struct file_operations grsec_fops = {
69156+ .read = read_learn,
69157+ .write = write_grsec_handler,
69158+ .open = open_learn,
69159+ .release = close_learn,
69160+ .poll = poll_learn,
69161+};
69162diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
69163new file mode 100644
69164index 0000000..39645c9
69165--- /dev/null
69166+++ b/grsecurity/gracl_res.c
69167@@ -0,0 +1,68 @@
69168+#include <linux/kernel.h>
69169+#include <linux/sched.h>
69170+#include <linux/gracl.h>
69171+#include <linux/grinternal.h>
69172+
69173+static const char *restab_log[] = {
69174+ [RLIMIT_CPU] = "RLIMIT_CPU",
69175+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
69176+ [RLIMIT_DATA] = "RLIMIT_DATA",
69177+ [RLIMIT_STACK] = "RLIMIT_STACK",
69178+ [RLIMIT_CORE] = "RLIMIT_CORE",
69179+ [RLIMIT_RSS] = "RLIMIT_RSS",
69180+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
69181+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
69182+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
69183+ [RLIMIT_AS] = "RLIMIT_AS",
69184+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
69185+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
69186+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
69187+ [RLIMIT_NICE] = "RLIMIT_NICE",
69188+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
69189+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
69190+ [GR_CRASH_RES] = "RLIMIT_CRASH"
69191+};
69192+
69193+void
69194+gr_log_resource(const struct task_struct *task,
69195+ const int res, const unsigned long wanted, const int gt)
69196+{
69197+ const struct cred *cred;
69198+ unsigned long rlim;
69199+
69200+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
69201+ return;
69202+
69203+ // not yet supported resource
69204+ if (unlikely(!restab_log[res]))
69205+ return;
69206+
69207+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
69208+ rlim = task_rlimit_max(task, res);
69209+ else
69210+ rlim = task_rlimit(task, res);
69211+
69212+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
69213+ return;
69214+
69215+ rcu_read_lock();
69216+ cred = __task_cred(task);
69217+
69218+ if (res == RLIMIT_NPROC &&
69219+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
69220+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
69221+ goto out_rcu_unlock;
69222+ else if (res == RLIMIT_MEMLOCK &&
69223+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
69224+ goto out_rcu_unlock;
69225+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
69226+ goto out_rcu_unlock;
69227+ rcu_read_unlock();
69228+
69229+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
69230+
69231+ return;
69232+out_rcu_unlock:
69233+ rcu_read_unlock();
69234+ return;
69235+}
69236diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
69237new file mode 100644
69238index 0000000..3c38bfe
69239--- /dev/null
69240+++ b/grsecurity/gracl_segv.c
69241@@ -0,0 +1,305 @@
69242+#include <linux/kernel.h>
69243+#include <linux/mm.h>
69244+#include <asm/uaccess.h>
69245+#include <asm/errno.h>
69246+#include <asm/mman.h>
69247+#include <net/sock.h>
69248+#include <linux/file.h>
69249+#include <linux/fs.h>
69250+#include <linux/net.h>
69251+#include <linux/in.h>
69252+#include <linux/slab.h>
69253+#include <linux/types.h>
69254+#include <linux/sched.h>
69255+#include <linux/timer.h>
69256+#include <linux/gracl.h>
69257+#include <linux/grsecurity.h>
69258+#include <linux/grinternal.h>
69259+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69260+#include <linux/magic.h>
69261+#include <linux/pagemap.h>
69262+#include "../fs/btrfs/async-thread.h"
69263+#include "../fs/btrfs/ctree.h"
69264+#include "../fs/btrfs/btrfs_inode.h"
69265+#endif
69266+
69267+static struct crash_uid *uid_set;
69268+static unsigned short uid_used;
69269+static DEFINE_SPINLOCK(gr_uid_lock);
69270+extern rwlock_t gr_inode_lock;
69271+extern struct acl_subject_label *
69272+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
69273+ struct acl_role_label *role);
69274+
69275+static inline dev_t __get_dev(const struct dentry *dentry)
69276+{
69277+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69278+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69279+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69280+ else
69281+#endif
69282+ return dentry->d_sb->s_dev;
69283+}
69284+
69285+int
69286+gr_init_uidset(void)
69287+{
69288+ uid_set =
69289+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
69290+ uid_used = 0;
69291+
69292+ return uid_set ? 1 : 0;
69293+}
69294+
69295+void
69296+gr_free_uidset(void)
69297+{
69298+ if (uid_set)
69299+ kfree(uid_set);
69300+
69301+ return;
69302+}
69303+
69304+int
69305+gr_find_uid(const uid_t uid)
69306+{
69307+ struct crash_uid *tmp = uid_set;
69308+ uid_t buid;
69309+ int low = 0, high = uid_used - 1, mid;
69310+
69311+ while (high >= low) {
69312+ mid = (low + high) >> 1;
69313+ buid = tmp[mid].uid;
69314+ if (buid == uid)
69315+ return mid;
69316+ if (buid > uid)
69317+ high = mid - 1;
69318+ if (buid < uid)
69319+ low = mid + 1;
69320+ }
69321+
69322+ return -1;
69323+}
69324+
69325+static __inline__ void
69326+gr_insertsort(void)
69327+{
69328+ unsigned short i, j;
69329+ struct crash_uid index;
69330+
69331+ for (i = 1; i < uid_used; i++) {
69332+ index = uid_set[i];
69333+ j = i;
69334+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
69335+ uid_set[j] = uid_set[j - 1];
69336+ j--;
69337+ }
69338+ uid_set[j] = index;
69339+ }
69340+
69341+ return;
69342+}
69343+
69344+static __inline__ void
69345+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
69346+{
69347+ int loc;
69348+ uid_t uid = GR_GLOBAL_UID(kuid);
69349+
69350+ if (uid_used == GR_UIDTABLE_MAX)
69351+ return;
69352+
69353+ loc = gr_find_uid(uid);
69354+
69355+ if (loc >= 0) {
69356+ uid_set[loc].expires = expires;
69357+ return;
69358+ }
69359+
69360+ uid_set[uid_used].uid = uid;
69361+ uid_set[uid_used].expires = expires;
69362+ uid_used++;
69363+
69364+ gr_insertsort();
69365+
69366+ return;
69367+}
69368+
69369+void
69370+gr_remove_uid(const unsigned short loc)
69371+{
69372+ unsigned short i;
69373+
69374+ for (i = loc + 1; i < uid_used; i++)
69375+ uid_set[i - 1] = uid_set[i];
69376+
69377+ uid_used--;
69378+
69379+ return;
69380+}
69381+
69382+int
69383+gr_check_crash_uid(const kuid_t kuid)
69384+{
69385+ int loc;
69386+ int ret = 0;
69387+ uid_t uid;
69388+
69389+ if (unlikely(!gr_acl_is_enabled()))
69390+ return 0;
69391+
69392+ uid = GR_GLOBAL_UID(kuid);
69393+
69394+ spin_lock(&gr_uid_lock);
69395+ loc = gr_find_uid(uid);
69396+
69397+ if (loc < 0)
69398+ goto out_unlock;
69399+
69400+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
69401+ gr_remove_uid(loc);
69402+ else
69403+ ret = 1;
69404+
69405+out_unlock:
69406+ spin_unlock(&gr_uid_lock);
69407+ return ret;
69408+}
69409+
69410+static __inline__ int
69411+proc_is_setxid(const struct cred *cred)
69412+{
69413+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
69414+ !uid_eq(cred->uid, cred->fsuid))
69415+ return 1;
69416+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
69417+ !gid_eq(cred->gid, cred->fsgid))
69418+ return 1;
69419+
69420+ return 0;
69421+}
69422+
69423+extern int gr_fake_force_sig(int sig, struct task_struct *t);
69424+
69425+void
69426+gr_handle_crash(struct task_struct *task, const int sig)
69427+{
69428+ struct acl_subject_label *curr;
69429+ struct task_struct *tsk, *tsk2;
69430+ const struct cred *cred;
69431+ const struct cred *cred2;
69432+
69433+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
69434+ return;
69435+
69436+ if (unlikely(!gr_acl_is_enabled()))
69437+ return;
69438+
69439+ curr = task->acl;
69440+
69441+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
69442+ return;
69443+
69444+ if (time_before_eq(curr->expires, get_seconds())) {
69445+ curr->expires = 0;
69446+ curr->crashes = 0;
69447+ }
69448+
69449+ curr->crashes++;
69450+
69451+ if (!curr->expires)
69452+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
69453+
69454+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69455+ time_after(curr->expires, get_seconds())) {
69456+ rcu_read_lock();
69457+ cred = __task_cred(task);
69458+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
69459+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69460+ spin_lock(&gr_uid_lock);
69461+ gr_insert_uid(cred->uid, curr->expires);
69462+ spin_unlock(&gr_uid_lock);
69463+ curr->expires = 0;
69464+ curr->crashes = 0;
69465+ read_lock(&tasklist_lock);
69466+ do_each_thread(tsk2, tsk) {
69467+ cred2 = __task_cred(tsk);
69468+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
69469+ gr_fake_force_sig(SIGKILL, tsk);
69470+ } while_each_thread(tsk2, tsk);
69471+ read_unlock(&tasklist_lock);
69472+ } else {
69473+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69474+ read_lock(&tasklist_lock);
69475+ read_lock(&grsec_exec_file_lock);
69476+ do_each_thread(tsk2, tsk) {
69477+ if (likely(tsk != task)) {
69478+ // if this thread has the same subject as the one that triggered
69479+ // RES_CRASH and it's the same binary, kill it
69480+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
69481+ gr_fake_force_sig(SIGKILL, tsk);
69482+ }
69483+ } while_each_thread(tsk2, tsk);
69484+ read_unlock(&grsec_exec_file_lock);
69485+ read_unlock(&tasklist_lock);
69486+ }
69487+ rcu_read_unlock();
69488+ }
69489+
69490+ return;
69491+}
69492+
69493+int
69494+gr_check_crash_exec(const struct file *filp)
69495+{
69496+ struct acl_subject_label *curr;
69497+
69498+ if (unlikely(!gr_acl_is_enabled()))
69499+ return 0;
69500+
69501+ read_lock(&gr_inode_lock);
69502+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
69503+ __get_dev(filp->f_path.dentry),
69504+ current->role);
69505+ read_unlock(&gr_inode_lock);
69506+
69507+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
69508+ (!curr->crashes && !curr->expires))
69509+ return 0;
69510+
69511+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69512+ time_after(curr->expires, get_seconds()))
69513+ return 1;
69514+ else if (time_before_eq(curr->expires, get_seconds())) {
69515+ curr->crashes = 0;
69516+ curr->expires = 0;
69517+ }
69518+
69519+ return 0;
69520+}
69521+
69522+void
69523+gr_handle_alertkill(struct task_struct *task)
69524+{
69525+ struct acl_subject_label *curracl;
69526+ __u32 curr_ip;
69527+ struct task_struct *p, *p2;
69528+
69529+ if (unlikely(!gr_acl_is_enabled()))
69530+ return;
69531+
69532+ curracl = task->acl;
69533+ curr_ip = task->signal->curr_ip;
69534+
69535+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
69536+ read_lock(&tasklist_lock);
69537+ do_each_thread(p2, p) {
69538+ if (p->signal->curr_ip == curr_ip)
69539+ gr_fake_force_sig(SIGKILL, p);
69540+ } while_each_thread(p2, p);
69541+ read_unlock(&tasklist_lock);
69542+ } else if (curracl->mode & GR_KILLPROC)
69543+ gr_fake_force_sig(SIGKILL, task);
69544+
69545+ return;
69546+}
69547diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
69548new file mode 100644
69549index 0000000..98011b0
69550--- /dev/null
69551+++ b/grsecurity/gracl_shm.c
69552@@ -0,0 +1,40 @@
69553+#include <linux/kernel.h>
69554+#include <linux/mm.h>
69555+#include <linux/sched.h>
69556+#include <linux/file.h>
69557+#include <linux/ipc.h>
69558+#include <linux/gracl.h>
69559+#include <linux/grsecurity.h>
69560+#include <linux/grinternal.h>
69561+
69562+int
69563+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69564+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69565+{
69566+ struct task_struct *task;
69567+
69568+ if (!gr_acl_is_enabled())
69569+ return 1;
69570+
69571+ rcu_read_lock();
69572+ read_lock(&tasklist_lock);
69573+
69574+ task = find_task_by_vpid(shm_cprid);
69575+
69576+ if (unlikely(!task))
69577+ task = find_task_by_vpid(shm_lapid);
69578+
69579+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
69580+ (task_pid_nr(task) == shm_lapid)) &&
69581+ (task->acl->mode & GR_PROTSHM) &&
69582+ (task->acl != current->acl))) {
69583+ read_unlock(&tasklist_lock);
69584+ rcu_read_unlock();
69585+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
69586+ return 0;
69587+ }
69588+ read_unlock(&tasklist_lock);
69589+ rcu_read_unlock();
69590+
69591+ return 1;
69592+}
69593diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
69594new file mode 100644
69595index 0000000..bc0be01
69596--- /dev/null
69597+++ b/grsecurity/grsec_chdir.c
69598@@ -0,0 +1,19 @@
69599+#include <linux/kernel.h>
69600+#include <linux/sched.h>
69601+#include <linux/fs.h>
69602+#include <linux/file.h>
69603+#include <linux/grsecurity.h>
69604+#include <linux/grinternal.h>
69605+
69606+void
69607+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
69608+{
69609+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69610+ if ((grsec_enable_chdir && grsec_enable_group &&
69611+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
69612+ !grsec_enable_group)) {
69613+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
69614+ }
69615+#endif
69616+ return;
69617+}
69618diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
69619new file mode 100644
69620index 0000000..bd6e105
69621--- /dev/null
69622+++ b/grsecurity/grsec_chroot.c
69623@@ -0,0 +1,370 @@
69624+#include <linux/kernel.h>
69625+#include <linux/module.h>
69626+#include <linux/sched.h>
69627+#include <linux/file.h>
69628+#include <linux/fs.h>
69629+#include <linux/mount.h>
69630+#include <linux/types.h>
69631+#include "../fs/mount.h"
69632+#include <linux/grsecurity.h>
69633+#include <linux/grinternal.h>
69634+
69635+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69636+static int gr_init_ran;
69637+#endif
69638+
69639+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
69640+{
69641+#ifdef CONFIG_GRKERNSEC
69642+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
69643+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
69644+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69645+ && gr_init_ran
69646+#endif
69647+ )
69648+ task->gr_is_chrooted = 1;
69649+ else {
69650+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69651+ if (task_pid_nr(task) == 1 && !gr_init_ran)
69652+ gr_init_ran = 1;
69653+#endif
69654+ task->gr_is_chrooted = 0;
69655+ }
69656+
69657+ task->gr_chroot_dentry = path->dentry;
69658+#endif
69659+ return;
69660+}
69661+
69662+void gr_clear_chroot_entries(struct task_struct *task)
69663+{
69664+#ifdef CONFIG_GRKERNSEC
69665+ task->gr_is_chrooted = 0;
69666+ task->gr_chroot_dentry = NULL;
69667+#endif
69668+ return;
69669+}
69670+
69671+int
69672+gr_handle_chroot_unix(const pid_t pid)
69673+{
69674+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69675+ struct task_struct *p;
69676+
69677+ if (unlikely(!grsec_enable_chroot_unix))
69678+ return 1;
69679+
69680+ if (likely(!proc_is_chrooted(current)))
69681+ return 1;
69682+
69683+ rcu_read_lock();
69684+ read_lock(&tasklist_lock);
69685+ p = find_task_by_vpid_unrestricted(pid);
69686+ if (unlikely(p && !have_same_root(current, p))) {
69687+ read_unlock(&tasklist_lock);
69688+ rcu_read_unlock();
69689+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
69690+ return 0;
69691+ }
69692+ read_unlock(&tasklist_lock);
69693+ rcu_read_unlock();
69694+#endif
69695+ return 1;
69696+}
69697+
69698+int
69699+gr_handle_chroot_nice(void)
69700+{
69701+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69702+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
69703+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
69704+ return -EPERM;
69705+ }
69706+#endif
69707+ return 0;
69708+}
69709+
69710+int
69711+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
69712+{
69713+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69714+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
69715+ && proc_is_chrooted(current)) {
69716+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
69717+ return -EACCES;
69718+ }
69719+#endif
69720+ return 0;
69721+}
69722+
69723+int
69724+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
69725+{
69726+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69727+ struct task_struct *p;
69728+ int ret = 0;
69729+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
69730+ return ret;
69731+
69732+ read_lock(&tasklist_lock);
69733+ do_each_pid_task(pid, type, p) {
69734+ if (!have_same_root(current, p)) {
69735+ ret = 1;
69736+ goto out;
69737+ }
69738+ } while_each_pid_task(pid, type, p);
69739+out:
69740+ read_unlock(&tasklist_lock);
69741+ return ret;
69742+#endif
69743+ return 0;
69744+}
69745+
69746+int
69747+gr_pid_is_chrooted(struct task_struct *p)
69748+{
69749+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69750+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
69751+ return 0;
69752+
69753+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
69754+ !have_same_root(current, p)) {
69755+ return 1;
69756+ }
69757+#endif
69758+ return 0;
69759+}
69760+
69761+EXPORT_SYMBOL(gr_pid_is_chrooted);
69762+
69763+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
69764+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
69765+{
69766+ struct path path, currentroot;
69767+ int ret = 0;
69768+
69769+ path.dentry = (struct dentry *)u_dentry;
69770+ path.mnt = (struct vfsmount *)u_mnt;
69771+ get_fs_root(current->fs, &currentroot);
69772+ if (path_is_under(&path, &currentroot))
69773+ ret = 1;
69774+ path_put(&currentroot);
69775+
69776+ return ret;
69777+}
69778+#endif
69779+
69780+int
69781+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
69782+{
69783+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69784+ if (!grsec_enable_chroot_fchdir)
69785+ return 1;
69786+
69787+ if (!proc_is_chrooted(current))
69788+ return 1;
69789+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
69790+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
69791+ return 0;
69792+ }
69793+#endif
69794+ return 1;
69795+}
69796+
69797+int
69798+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69799+ const time_t shm_createtime)
69800+{
69801+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69802+ struct task_struct *p;
69803+ time_t starttime;
69804+
69805+ if (unlikely(!grsec_enable_chroot_shmat))
69806+ return 1;
69807+
69808+ if (likely(!proc_is_chrooted(current)))
69809+ return 1;
69810+
69811+ rcu_read_lock();
69812+ read_lock(&tasklist_lock);
69813+
69814+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
69815+ starttime = p->start_time.tv_sec;
69816+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
69817+ if (have_same_root(current, p)) {
69818+ goto allow;
69819+ } else {
69820+ read_unlock(&tasklist_lock);
69821+ rcu_read_unlock();
69822+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69823+ return 0;
69824+ }
69825+ }
69826+ /* creator exited, pid reuse, fall through to next check */
69827+ }
69828+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
69829+ if (unlikely(!have_same_root(current, p))) {
69830+ read_unlock(&tasklist_lock);
69831+ rcu_read_unlock();
69832+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69833+ return 0;
69834+ }
69835+ }
69836+
69837+allow:
69838+ read_unlock(&tasklist_lock);
69839+ rcu_read_unlock();
69840+#endif
69841+ return 1;
69842+}
69843+
69844+void
69845+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
69846+{
69847+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69848+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
69849+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
69850+#endif
69851+ return;
69852+}
69853+
69854+int
69855+gr_handle_chroot_mknod(const struct dentry *dentry,
69856+ const struct vfsmount *mnt, const int mode)
69857+{
69858+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69859+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
69860+ proc_is_chrooted(current)) {
69861+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
69862+ return -EPERM;
69863+ }
69864+#endif
69865+ return 0;
69866+}
69867+
69868+int
69869+gr_handle_chroot_mount(const struct dentry *dentry,
69870+ const struct vfsmount *mnt, const char *dev_name)
69871+{
69872+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69873+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
69874+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
69875+ return -EPERM;
69876+ }
69877+#endif
69878+ return 0;
69879+}
69880+
69881+int
69882+gr_handle_chroot_pivot(void)
69883+{
69884+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69885+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
69886+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
69887+ return -EPERM;
69888+ }
69889+#endif
69890+ return 0;
69891+}
69892+
69893+int
69894+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
69895+{
69896+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69897+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
69898+ !gr_is_outside_chroot(dentry, mnt)) {
69899+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
69900+ return -EPERM;
69901+ }
69902+#endif
69903+ return 0;
69904+}
69905+
69906+extern const char *captab_log[];
69907+extern int captab_log_entries;
69908+
69909+int
69910+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69911+{
69912+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69913+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69914+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69915+ if (cap_raised(chroot_caps, cap)) {
69916+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
69917+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
69918+ }
69919+ return 0;
69920+ }
69921+ }
69922+#endif
69923+ return 1;
69924+}
69925+
69926+int
69927+gr_chroot_is_capable(const int cap)
69928+{
69929+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69930+ return gr_task_chroot_is_capable(current, current_cred(), cap);
69931+#endif
69932+ return 1;
69933+}
69934+
69935+int
69936+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
69937+{
69938+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69939+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69940+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69941+ if (cap_raised(chroot_caps, cap)) {
69942+ return 0;
69943+ }
69944+ }
69945+#endif
69946+ return 1;
69947+}
69948+
69949+int
69950+gr_chroot_is_capable_nolog(const int cap)
69951+{
69952+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69953+ return gr_task_chroot_is_capable_nolog(current, cap);
69954+#endif
69955+ return 1;
69956+}
69957+
69958+int
69959+gr_handle_chroot_sysctl(const int op)
69960+{
69961+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69962+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
69963+ proc_is_chrooted(current))
69964+ return -EACCES;
69965+#endif
69966+ return 0;
69967+}
69968+
69969+void
69970+gr_handle_chroot_chdir(const struct path *path)
69971+{
69972+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69973+ if (grsec_enable_chroot_chdir)
69974+ set_fs_pwd(current->fs, path);
69975+#endif
69976+ return;
69977+}
69978+
69979+int
69980+gr_handle_chroot_chmod(const struct dentry *dentry,
69981+ const struct vfsmount *mnt, const int mode)
69982+{
69983+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69984+ /* allow chmod +s on directories, but not files */
69985+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
69986+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
69987+ proc_is_chrooted(current)) {
69988+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
69989+ return -EPERM;
69990+ }
69991+#endif
69992+ return 0;
69993+}
69994diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
69995new file mode 100644
69996index 0000000..ce65ceb
69997--- /dev/null
69998+++ b/grsecurity/grsec_disabled.c
69999@@ -0,0 +1,434 @@
70000+#include <linux/kernel.h>
70001+#include <linux/module.h>
70002+#include <linux/sched.h>
70003+#include <linux/file.h>
70004+#include <linux/fs.h>
70005+#include <linux/kdev_t.h>
70006+#include <linux/net.h>
70007+#include <linux/in.h>
70008+#include <linux/ip.h>
70009+#include <linux/skbuff.h>
70010+#include <linux/sysctl.h>
70011+
70012+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
70013+void
70014+pax_set_initial_flags(struct linux_binprm *bprm)
70015+{
70016+ return;
70017+}
70018+#endif
70019+
70020+#ifdef CONFIG_SYSCTL
70021+__u32
70022+gr_handle_sysctl(const struct ctl_table * table, const int op)
70023+{
70024+ return 0;
70025+}
70026+#endif
70027+
70028+#ifdef CONFIG_TASKSTATS
70029+int gr_is_taskstats_denied(int pid)
70030+{
70031+ return 0;
70032+}
70033+#endif
70034+
70035+int
70036+gr_acl_is_enabled(void)
70037+{
70038+ return 0;
70039+}
70040+
70041+void
70042+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
70043+{
70044+ return;
70045+}
70046+
70047+int
70048+gr_handle_rawio(const struct inode *inode)
70049+{
70050+ return 0;
70051+}
70052+
70053+void
70054+gr_acl_handle_psacct(struct task_struct *task, const long code)
70055+{
70056+ return;
70057+}
70058+
70059+int
70060+gr_handle_ptrace(struct task_struct *task, const long request)
70061+{
70062+ return 0;
70063+}
70064+
70065+int
70066+gr_handle_proc_ptrace(struct task_struct *task)
70067+{
70068+ return 0;
70069+}
70070+
70071+int
70072+gr_set_acls(const int type)
70073+{
70074+ return 0;
70075+}
70076+
70077+int
70078+gr_check_hidden_task(const struct task_struct *tsk)
70079+{
70080+ return 0;
70081+}
70082+
70083+int
70084+gr_check_protected_task(const struct task_struct *task)
70085+{
70086+ return 0;
70087+}
70088+
70089+int
70090+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70091+{
70092+ return 0;
70093+}
70094+
70095+void
70096+gr_copy_label(struct task_struct *tsk)
70097+{
70098+ return;
70099+}
70100+
70101+void
70102+gr_set_pax_flags(struct task_struct *task)
70103+{
70104+ return;
70105+}
70106+
70107+int
70108+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
70109+ const int unsafe_share)
70110+{
70111+ return 0;
70112+}
70113+
70114+void
70115+gr_handle_delete(const ino_t ino, const dev_t dev)
70116+{
70117+ return;
70118+}
70119+
70120+void
70121+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
70122+{
70123+ return;
70124+}
70125+
70126+void
70127+gr_handle_crash(struct task_struct *task, const int sig)
70128+{
70129+ return;
70130+}
70131+
70132+int
70133+gr_check_crash_exec(const struct file *filp)
70134+{
70135+ return 0;
70136+}
70137+
70138+int
70139+gr_check_crash_uid(const kuid_t uid)
70140+{
70141+ return 0;
70142+}
70143+
70144+void
70145+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
70146+ struct dentry *old_dentry,
70147+ struct dentry *new_dentry,
70148+ struct vfsmount *mnt, const __u8 replace)
70149+{
70150+ return;
70151+}
70152+
70153+int
70154+gr_search_socket(const int family, const int type, const int protocol)
70155+{
70156+ return 1;
70157+}
70158+
70159+int
70160+gr_search_connectbind(const int mode, const struct socket *sock,
70161+ const struct sockaddr_in *addr)
70162+{
70163+ return 0;
70164+}
70165+
70166+void
70167+gr_handle_alertkill(struct task_struct *task)
70168+{
70169+ return;
70170+}
70171+
70172+__u32
70173+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
70174+{
70175+ return 1;
70176+}
70177+
70178+__u32
70179+gr_acl_handle_hidden_file(const struct dentry * dentry,
70180+ const struct vfsmount * mnt)
70181+{
70182+ return 1;
70183+}
70184+
70185+__u32
70186+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70187+ int acc_mode)
70188+{
70189+ return 1;
70190+}
70191+
70192+__u32
70193+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70194+{
70195+ return 1;
70196+}
70197+
70198+__u32
70199+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
70200+{
70201+ return 1;
70202+}
70203+
70204+int
70205+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
70206+ unsigned int *vm_flags)
70207+{
70208+ return 1;
70209+}
70210+
70211+__u32
70212+gr_acl_handle_truncate(const struct dentry * dentry,
70213+ const struct vfsmount * mnt)
70214+{
70215+ return 1;
70216+}
70217+
70218+__u32
70219+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
70220+{
70221+ return 1;
70222+}
70223+
70224+__u32
70225+gr_acl_handle_access(const struct dentry * dentry,
70226+ const struct vfsmount * mnt, const int fmode)
70227+{
70228+ return 1;
70229+}
70230+
70231+__u32
70232+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
70233+ umode_t *mode)
70234+{
70235+ return 1;
70236+}
70237+
70238+__u32
70239+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
70240+{
70241+ return 1;
70242+}
70243+
70244+__u32
70245+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
70246+{
70247+ return 1;
70248+}
70249+
70250+void
70251+grsecurity_init(void)
70252+{
70253+ return;
70254+}
70255+
70256+umode_t gr_acl_umask(void)
70257+{
70258+ return 0;
70259+}
70260+
70261+__u32
70262+gr_acl_handle_mknod(const struct dentry * new_dentry,
70263+ const struct dentry * parent_dentry,
70264+ const struct vfsmount * parent_mnt,
70265+ const int mode)
70266+{
70267+ return 1;
70268+}
70269+
70270+__u32
70271+gr_acl_handle_mkdir(const struct dentry * new_dentry,
70272+ const struct dentry * parent_dentry,
70273+ const struct vfsmount * parent_mnt)
70274+{
70275+ return 1;
70276+}
70277+
70278+__u32
70279+gr_acl_handle_symlink(const struct dentry * new_dentry,
70280+ const struct dentry * parent_dentry,
70281+ const struct vfsmount * parent_mnt, const struct filename *from)
70282+{
70283+ return 1;
70284+}
70285+
70286+__u32
70287+gr_acl_handle_link(const struct dentry * new_dentry,
70288+ const struct dentry * parent_dentry,
70289+ const struct vfsmount * parent_mnt,
70290+ const struct dentry * old_dentry,
70291+ const struct vfsmount * old_mnt, const struct filename *to)
70292+{
70293+ return 1;
70294+}
70295+
70296+int
70297+gr_acl_handle_rename(const struct dentry *new_dentry,
70298+ const struct dentry *parent_dentry,
70299+ const struct vfsmount *parent_mnt,
70300+ const struct dentry *old_dentry,
70301+ const struct inode *old_parent_inode,
70302+ const struct vfsmount *old_mnt, const struct filename *newname)
70303+{
70304+ return 0;
70305+}
70306+
70307+int
70308+gr_acl_handle_filldir(const struct file *file, const char *name,
70309+ const int namelen, const ino_t ino)
70310+{
70311+ return 1;
70312+}
70313+
70314+int
70315+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70316+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
70317+{
70318+ return 1;
70319+}
70320+
70321+int
70322+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
70323+{
70324+ return 0;
70325+}
70326+
70327+int
70328+gr_search_accept(const struct socket *sock)
70329+{
70330+ return 0;
70331+}
70332+
70333+int
70334+gr_search_listen(const struct socket *sock)
70335+{
70336+ return 0;
70337+}
70338+
70339+int
70340+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
70341+{
70342+ return 0;
70343+}
70344+
70345+__u32
70346+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
70347+{
70348+ return 1;
70349+}
70350+
70351+__u32
70352+gr_acl_handle_creat(const struct dentry * dentry,
70353+ const struct dentry * p_dentry,
70354+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70355+ const int imode)
70356+{
70357+ return 1;
70358+}
70359+
70360+void
70361+gr_acl_handle_exit(void)
70362+{
70363+ return;
70364+}
70365+
70366+int
70367+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
70368+{
70369+ return 1;
70370+}
70371+
70372+void
70373+gr_set_role_label(const kuid_t uid, const kgid_t gid)
70374+{
70375+ return;
70376+}
70377+
70378+int
70379+gr_acl_handle_procpidmem(const struct task_struct *task)
70380+{
70381+ return 0;
70382+}
70383+
70384+int
70385+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
70386+{
70387+ return 0;
70388+}
70389+
70390+int
70391+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
70392+{
70393+ return 0;
70394+}
70395+
70396+void
70397+gr_set_kernel_label(struct task_struct *task)
70398+{
70399+ return;
70400+}
70401+
70402+int
70403+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70404+{
70405+ return 0;
70406+}
70407+
70408+int
70409+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70410+{
70411+ return 0;
70412+}
70413+
70414+int gr_acl_enable_at_secure(void)
70415+{
70416+ return 0;
70417+}
70418+
70419+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70420+{
70421+ return dentry->d_sb->s_dev;
70422+}
70423+
70424+void gr_put_exec_file(struct task_struct *task)
70425+{
70426+ return;
70427+}
70428+
70429+EXPORT_SYMBOL(gr_set_kernel_label);
70430+#ifdef CONFIG_SECURITY
70431+EXPORT_SYMBOL(gr_check_user_change);
70432+EXPORT_SYMBOL(gr_check_group_change);
70433+#endif
70434diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
70435new file mode 100644
70436index 0000000..387032b
70437--- /dev/null
70438+++ b/grsecurity/grsec_exec.c
70439@@ -0,0 +1,187 @@
70440+#include <linux/kernel.h>
70441+#include <linux/sched.h>
70442+#include <linux/file.h>
70443+#include <linux/binfmts.h>
70444+#include <linux/fs.h>
70445+#include <linux/types.h>
70446+#include <linux/grdefs.h>
70447+#include <linux/grsecurity.h>
70448+#include <linux/grinternal.h>
70449+#include <linux/capability.h>
70450+#include <linux/module.h>
70451+#include <linux/compat.h>
70452+
70453+#include <asm/uaccess.h>
70454+
70455+#ifdef CONFIG_GRKERNSEC_EXECLOG
70456+static char gr_exec_arg_buf[132];
70457+static DEFINE_MUTEX(gr_exec_arg_mutex);
70458+#endif
70459+
70460+struct user_arg_ptr {
70461+#ifdef CONFIG_COMPAT
70462+ bool is_compat;
70463+#endif
70464+ union {
70465+ const char __user *const __user *native;
70466+#ifdef CONFIG_COMPAT
70467+ const compat_uptr_t __user *compat;
70468+#endif
70469+ } ptr;
70470+};
70471+
70472+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
70473+
70474+void
70475+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
70476+{
70477+#ifdef CONFIG_GRKERNSEC_EXECLOG
70478+ char *grarg = gr_exec_arg_buf;
70479+ unsigned int i, x, execlen = 0;
70480+ char c;
70481+
70482+ if (!((grsec_enable_execlog && grsec_enable_group &&
70483+ in_group_p(grsec_audit_gid))
70484+ || (grsec_enable_execlog && !grsec_enable_group)))
70485+ return;
70486+
70487+ mutex_lock(&gr_exec_arg_mutex);
70488+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
70489+
70490+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
70491+ const char __user *p;
70492+ unsigned int len;
70493+
70494+ p = get_user_arg_ptr(argv, i);
70495+ if (IS_ERR(p))
70496+ goto log;
70497+
70498+ len = strnlen_user(p, 128 - execlen);
70499+ if (len > 128 - execlen)
70500+ len = 128 - execlen;
70501+ else if (len > 0)
70502+ len--;
70503+ if (copy_from_user(grarg + execlen, p, len))
70504+ goto log;
70505+
70506+ /* rewrite unprintable characters */
70507+ for (x = 0; x < len; x++) {
70508+ c = *(grarg + execlen + x);
70509+ if (c < 32 || c > 126)
70510+ *(grarg + execlen + x) = ' ';
70511+ }
70512+
70513+ execlen += len;
70514+ *(grarg + execlen) = ' ';
70515+ *(grarg + execlen + 1) = '\0';
70516+ execlen++;
70517+ }
70518+
70519+ log:
70520+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
70521+ bprm->file->f_path.mnt, grarg);
70522+ mutex_unlock(&gr_exec_arg_mutex);
70523+#endif
70524+ return;
70525+}
70526+
70527+#ifdef CONFIG_GRKERNSEC
70528+extern int gr_acl_is_capable(const int cap);
70529+extern int gr_acl_is_capable_nolog(const int cap);
70530+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70531+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
70532+extern int gr_chroot_is_capable(const int cap);
70533+extern int gr_chroot_is_capable_nolog(const int cap);
70534+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70535+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
70536+#endif
70537+
70538+const char *captab_log[] = {
70539+ "CAP_CHOWN",
70540+ "CAP_DAC_OVERRIDE",
70541+ "CAP_DAC_READ_SEARCH",
70542+ "CAP_FOWNER",
70543+ "CAP_FSETID",
70544+ "CAP_KILL",
70545+ "CAP_SETGID",
70546+ "CAP_SETUID",
70547+ "CAP_SETPCAP",
70548+ "CAP_LINUX_IMMUTABLE",
70549+ "CAP_NET_BIND_SERVICE",
70550+ "CAP_NET_BROADCAST",
70551+ "CAP_NET_ADMIN",
70552+ "CAP_NET_RAW",
70553+ "CAP_IPC_LOCK",
70554+ "CAP_IPC_OWNER",
70555+ "CAP_SYS_MODULE",
70556+ "CAP_SYS_RAWIO",
70557+ "CAP_SYS_CHROOT",
70558+ "CAP_SYS_PTRACE",
70559+ "CAP_SYS_PACCT",
70560+ "CAP_SYS_ADMIN",
70561+ "CAP_SYS_BOOT",
70562+ "CAP_SYS_NICE",
70563+ "CAP_SYS_RESOURCE",
70564+ "CAP_SYS_TIME",
70565+ "CAP_SYS_TTY_CONFIG",
70566+ "CAP_MKNOD",
70567+ "CAP_LEASE",
70568+ "CAP_AUDIT_WRITE",
70569+ "CAP_AUDIT_CONTROL",
70570+ "CAP_SETFCAP",
70571+ "CAP_MAC_OVERRIDE",
70572+ "CAP_MAC_ADMIN",
70573+ "CAP_SYSLOG",
70574+ "CAP_WAKE_ALARM"
70575+};
70576+
70577+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
70578+
70579+int gr_is_capable(const int cap)
70580+{
70581+#ifdef CONFIG_GRKERNSEC
70582+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
70583+ return 1;
70584+ return 0;
70585+#else
70586+ return 1;
70587+#endif
70588+}
70589+
70590+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70591+{
70592+#ifdef CONFIG_GRKERNSEC
70593+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
70594+ return 1;
70595+ return 0;
70596+#else
70597+ return 1;
70598+#endif
70599+}
70600+
70601+int gr_is_capable_nolog(const int cap)
70602+{
70603+#ifdef CONFIG_GRKERNSEC
70604+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
70605+ return 1;
70606+ return 0;
70607+#else
70608+ return 1;
70609+#endif
70610+}
70611+
70612+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
70613+{
70614+#ifdef CONFIG_GRKERNSEC
70615+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
70616+ return 1;
70617+ return 0;
70618+#else
70619+ return 1;
70620+#endif
70621+}
70622+
70623+EXPORT_SYMBOL(gr_is_capable);
70624+EXPORT_SYMBOL(gr_is_capable_nolog);
70625+EXPORT_SYMBOL(gr_task_is_capable);
70626+EXPORT_SYMBOL(gr_task_is_capable_nolog);
70627diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
70628new file mode 100644
70629index 0000000..06cc6ea
70630--- /dev/null
70631+++ b/grsecurity/grsec_fifo.c
70632@@ -0,0 +1,24 @@
70633+#include <linux/kernel.h>
70634+#include <linux/sched.h>
70635+#include <linux/fs.h>
70636+#include <linux/file.h>
70637+#include <linux/grinternal.h>
70638+
70639+int
70640+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
70641+ const struct dentry *dir, const int flag, const int acc_mode)
70642+{
70643+#ifdef CONFIG_GRKERNSEC_FIFO
70644+ const struct cred *cred = current_cred();
70645+
70646+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
70647+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
70648+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
70649+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
70650+ if (!inode_permission(dentry->d_inode, acc_mode))
70651+ 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));
70652+ return -EACCES;
70653+ }
70654+#endif
70655+ return 0;
70656+}
70657diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
70658new file mode 100644
70659index 0000000..8ca18bf
70660--- /dev/null
70661+++ b/grsecurity/grsec_fork.c
70662@@ -0,0 +1,23 @@
70663+#include <linux/kernel.h>
70664+#include <linux/sched.h>
70665+#include <linux/grsecurity.h>
70666+#include <linux/grinternal.h>
70667+#include <linux/errno.h>
70668+
70669+void
70670+gr_log_forkfail(const int retval)
70671+{
70672+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70673+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
70674+ switch (retval) {
70675+ case -EAGAIN:
70676+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
70677+ break;
70678+ case -ENOMEM:
70679+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
70680+ break;
70681+ }
70682+ }
70683+#endif
70684+ return;
70685+}
70686diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
70687new file mode 100644
70688index 0000000..99a0cb9
70689--- /dev/null
70690+++ b/grsecurity/grsec_init.c
70691@@ -0,0 +1,283 @@
70692+#include <linux/kernel.h>
70693+#include <linux/sched.h>
70694+#include <linux/mm.h>
70695+#include <linux/gracl.h>
70696+#include <linux/slab.h>
70697+#include <linux/vmalloc.h>
70698+#include <linux/percpu.h>
70699+#include <linux/module.h>
70700+
70701+int grsec_enable_ptrace_readexec;
70702+int grsec_enable_setxid;
70703+int grsec_enable_symlinkown;
70704+kgid_t grsec_symlinkown_gid;
70705+int grsec_enable_brute;
70706+int grsec_enable_link;
70707+int grsec_enable_dmesg;
70708+int grsec_enable_harden_ptrace;
70709+int grsec_enable_fifo;
70710+int grsec_enable_execlog;
70711+int grsec_enable_signal;
70712+int grsec_enable_forkfail;
70713+int grsec_enable_audit_ptrace;
70714+int grsec_enable_time;
70715+int grsec_enable_group;
70716+kgid_t grsec_audit_gid;
70717+int grsec_enable_chdir;
70718+int grsec_enable_mount;
70719+int grsec_enable_rofs;
70720+int grsec_deny_new_usb;
70721+int grsec_enable_chroot_findtask;
70722+int grsec_enable_chroot_mount;
70723+int grsec_enable_chroot_shmat;
70724+int grsec_enable_chroot_fchdir;
70725+int grsec_enable_chroot_double;
70726+int grsec_enable_chroot_pivot;
70727+int grsec_enable_chroot_chdir;
70728+int grsec_enable_chroot_chmod;
70729+int grsec_enable_chroot_mknod;
70730+int grsec_enable_chroot_nice;
70731+int grsec_enable_chroot_execlog;
70732+int grsec_enable_chroot_caps;
70733+int grsec_enable_chroot_sysctl;
70734+int grsec_enable_chroot_unix;
70735+int grsec_enable_tpe;
70736+kgid_t grsec_tpe_gid;
70737+int grsec_enable_blackhole;
70738+#ifdef CONFIG_IPV6_MODULE
70739+EXPORT_SYMBOL(grsec_enable_blackhole);
70740+#endif
70741+int grsec_lastack_retries;
70742+int grsec_enable_tpe_all;
70743+int grsec_enable_tpe_invert;
70744+int grsec_enable_socket_all;
70745+kgid_t grsec_socket_all_gid;
70746+int grsec_enable_socket_client;
70747+kgid_t grsec_socket_client_gid;
70748+int grsec_enable_socket_server;
70749+kgid_t grsec_socket_server_gid;
70750+int grsec_resource_logging;
70751+int grsec_disable_privio;
70752+int grsec_enable_log_rwxmaps;
70753+int grsec_lock;
70754+
70755+DEFINE_SPINLOCK(grsec_alert_lock);
70756+unsigned long grsec_alert_wtime = 0;
70757+unsigned long grsec_alert_fyet = 0;
70758+
70759+DEFINE_SPINLOCK(grsec_audit_lock);
70760+
70761+DEFINE_RWLOCK(grsec_exec_file_lock);
70762+
70763+char *gr_shared_page[4];
70764+
70765+char *gr_alert_log_fmt;
70766+char *gr_audit_log_fmt;
70767+char *gr_alert_log_buf;
70768+char *gr_audit_log_buf;
70769+
70770+extern struct gr_arg *gr_usermode;
70771+extern unsigned char *gr_system_salt;
70772+extern unsigned char *gr_system_sum;
70773+
70774+void __init
70775+grsecurity_init(void)
70776+{
70777+ int j;
70778+ /* create the per-cpu shared pages */
70779+
70780+#ifdef CONFIG_X86
70781+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
70782+#endif
70783+
70784+ for (j = 0; j < 4; j++) {
70785+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
70786+ if (gr_shared_page[j] == NULL) {
70787+ panic("Unable to allocate grsecurity shared page");
70788+ return;
70789+ }
70790+ }
70791+
70792+ /* allocate log buffers */
70793+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
70794+ if (!gr_alert_log_fmt) {
70795+ panic("Unable to allocate grsecurity alert log format buffer");
70796+ return;
70797+ }
70798+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
70799+ if (!gr_audit_log_fmt) {
70800+ panic("Unable to allocate grsecurity audit log format buffer");
70801+ return;
70802+ }
70803+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70804+ if (!gr_alert_log_buf) {
70805+ panic("Unable to allocate grsecurity alert log buffer");
70806+ return;
70807+ }
70808+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70809+ if (!gr_audit_log_buf) {
70810+ panic("Unable to allocate grsecurity audit log buffer");
70811+ return;
70812+ }
70813+
70814+ /* allocate memory for authentication structure */
70815+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
70816+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
70817+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
70818+
70819+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
70820+ panic("Unable to allocate grsecurity authentication structure");
70821+ return;
70822+ }
70823+
70824+
70825+#ifdef CONFIG_GRKERNSEC_IO
70826+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
70827+ grsec_disable_privio = 1;
70828+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70829+ grsec_disable_privio = 1;
70830+#else
70831+ grsec_disable_privio = 0;
70832+#endif
70833+#endif
70834+
70835+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
70836+ /* for backward compatibility, tpe_invert always defaults to on if
70837+ enabled in the kernel
70838+ */
70839+ grsec_enable_tpe_invert = 1;
70840+#endif
70841+
70842+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70843+#ifndef CONFIG_GRKERNSEC_SYSCTL
70844+ grsec_lock = 1;
70845+#endif
70846+
70847+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70848+ grsec_enable_log_rwxmaps = 1;
70849+#endif
70850+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
70851+ grsec_enable_group = 1;
70852+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
70853+#endif
70854+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70855+ grsec_enable_ptrace_readexec = 1;
70856+#endif
70857+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
70858+ grsec_enable_chdir = 1;
70859+#endif
70860+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
70861+ grsec_enable_harden_ptrace = 1;
70862+#endif
70863+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70864+ grsec_enable_mount = 1;
70865+#endif
70866+#ifdef CONFIG_GRKERNSEC_LINK
70867+ grsec_enable_link = 1;
70868+#endif
70869+#ifdef CONFIG_GRKERNSEC_BRUTE
70870+ grsec_enable_brute = 1;
70871+#endif
70872+#ifdef CONFIG_GRKERNSEC_DMESG
70873+ grsec_enable_dmesg = 1;
70874+#endif
70875+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70876+ grsec_enable_blackhole = 1;
70877+ grsec_lastack_retries = 4;
70878+#endif
70879+#ifdef CONFIG_GRKERNSEC_FIFO
70880+ grsec_enable_fifo = 1;
70881+#endif
70882+#ifdef CONFIG_GRKERNSEC_EXECLOG
70883+ grsec_enable_execlog = 1;
70884+#endif
70885+#ifdef CONFIG_GRKERNSEC_SETXID
70886+ grsec_enable_setxid = 1;
70887+#endif
70888+#ifdef CONFIG_GRKERNSEC_SIGNAL
70889+ grsec_enable_signal = 1;
70890+#endif
70891+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70892+ grsec_enable_forkfail = 1;
70893+#endif
70894+#ifdef CONFIG_GRKERNSEC_TIME
70895+ grsec_enable_time = 1;
70896+#endif
70897+#ifdef CONFIG_GRKERNSEC_RESLOG
70898+ grsec_resource_logging = 1;
70899+#endif
70900+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70901+ grsec_enable_chroot_findtask = 1;
70902+#endif
70903+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70904+ grsec_enable_chroot_unix = 1;
70905+#endif
70906+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70907+ grsec_enable_chroot_mount = 1;
70908+#endif
70909+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70910+ grsec_enable_chroot_fchdir = 1;
70911+#endif
70912+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70913+ grsec_enable_chroot_shmat = 1;
70914+#endif
70915+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70916+ grsec_enable_audit_ptrace = 1;
70917+#endif
70918+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70919+ grsec_enable_chroot_double = 1;
70920+#endif
70921+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70922+ grsec_enable_chroot_pivot = 1;
70923+#endif
70924+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70925+ grsec_enable_chroot_chdir = 1;
70926+#endif
70927+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70928+ grsec_enable_chroot_chmod = 1;
70929+#endif
70930+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70931+ grsec_enable_chroot_mknod = 1;
70932+#endif
70933+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70934+ grsec_enable_chroot_nice = 1;
70935+#endif
70936+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70937+ grsec_enable_chroot_execlog = 1;
70938+#endif
70939+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70940+ grsec_enable_chroot_caps = 1;
70941+#endif
70942+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70943+ grsec_enable_chroot_sysctl = 1;
70944+#endif
70945+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70946+ grsec_enable_symlinkown = 1;
70947+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
70948+#endif
70949+#ifdef CONFIG_GRKERNSEC_TPE
70950+ grsec_enable_tpe = 1;
70951+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
70952+#ifdef CONFIG_GRKERNSEC_TPE_ALL
70953+ grsec_enable_tpe_all = 1;
70954+#endif
70955+#endif
70956+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70957+ grsec_enable_socket_all = 1;
70958+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
70959+#endif
70960+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70961+ grsec_enable_socket_client = 1;
70962+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
70963+#endif
70964+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70965+ grsec_enable_socket_server = 1;
70966+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
70967+#endif
70968+#endif
70969+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
70970+ grsec_deny_new_usb = 1;
70971+#endif
70972+
70973+ return;
70974+}
70975diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
70976new file mode 100644
70977index 0000000..5e05e20
70978--- /dev/null
70979+++ b/grsecurity/grsec_link.c
70980@@ -0,0 +1,58 @@
70981+#include <linux/kernel.h>
70982+#include <linux/sched.h>
70983+#include <linux/fs.h>
70984+#include <linux/file.h>
70985+#include <linux/grinternal.h>
70986+
70987+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
70988+{
70989+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70990+ const struct inode *link_inode = link->dentry->d_inode;
70991+
70992+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
70993+ /* ignore root-owned links, e.g. /proc/self */
70994+ gr_is_global_nonroot(link_inode->i_uid) && target &&
70995+ !uid_eq(link_inode->i_uid, target->i_uid)) {
70996+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
70997+ return 1;
70998+ }
70999+#endif
71000+ return 0;
71001+}
71002+
71003+int
71004+gr_handle_follow_link(const struct inode *parent,
71005+ const struct inode *inode,
71006+ const struct dentry *dentry, const struct vfsmount *mnt)
71007+{
71008+#ifdef CONFIG_GRKERNSEC_LINK
71009+ const struct cred *cred = current_cred();
71010+
71011+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
71012+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
71013+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
71014+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
71015+ return -EACCES;
71016+ }
71017+#endif
71018+ return 0;
71019+}
71020+
71021+int
71022+gr_handle_hardlink(const struct dentry *dentry,
71023+ const struct vfsmount *mnt,
71024+ struct inode *inode, const int mode, const struct filename *to)
71025+{
71026+#ifdef CONFIG_GRKERNSEC_LINK
71027+ const struct cred *cred = current_cred();
71028+
71029+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
71030+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
71031+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
71032+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
71033+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
71034+ return -EPERM;
71035+ }
71036+#endif
71037+ return 0;
71038+}
71039diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
71040new file mode 100644
71041index 0000000..dbe0a6b
71042--- /dev/null
71043+++ b/grsecurity/grsec_log.c
71044@@ -0,0 +1,341 @@
71045+#include <linux/kernel.h>
71046+#include <linux/sched.h>
71047+#include <linux/file.h>
71048+#include <linux/tty.h>
71049+#include <linux/fs.h>
71050+#include <linux/mm.h>
71051+#include <linux/grinternal.h>
71052+
71053+#ifdef CONFIG_TREE_PREEMPT_RCU
71054+#define DISABLE_PREEMPT() preempt_disable()
71055+#define ENABLE_PREEMPT() preempt_enable()
71056+#else
71057+#define DISABLE_PREEMPT()
71058+#define ENABLE_PREEMPT()
71059+#endif
71060+
71061+#define BEGIN_LOCKS(x) \
71062+ DISABLE_PREEMPT(); \
71063+ rcu_read_lock(); \
71064+ read_lock(&tasklist_lock); \
71065+ read_lock(&grsec_exec_file_lock); \
71066+ if (x != GR_DO_AUDIT) \
71067+ spin_lock(&grsec_alert_lock); \
71068+ else \
71069+ spin_lock(&grsec_audit_lock)
71070+
71071+#define END_LOCKS(x) \
71072+ if (x != GR_DO_AUDIT) \
71073+ spin_unlock(&grsec_alert_lock); \
71074+ else \
71075+ spin_unlock(&grsec_audit_lock); \
71076+ read_unlock(&grsec_exec_file_lock); \
71077+ read_unlock(&tasklist_lock); \
71078+ rcu_read_unlock(); \
71079+ ENABLE_PREEMPT(); \
71080+ if (x == GR_DONT_AUDIT) \
71081+ gr_handle_alertkill(current)
71082+
71083+enum {
71084+ FLOODING,
71085+ NO_FLOODING
71086+};
71087+
71088+extern char *gr_alert_log_fmt;
71089+extern char *gr_audit_log_fmt;
71090+extern char *gr_alert_log_buf;
71091+extern char *gr_audit_log_buf;
71092+
71093+static int gr_log_start(int audit)
71094+{
71095+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
71096+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
71097+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71098+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
71099+ unsigned long curr_secs = get_seconds();
71100+
71101+ if (audit == GR_DO_AUDIT)
71102+ goto set_fmt;
71103+
71104+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
71105+ grsec_alert_wtime = curr_secs;
71106+ grsec_alert_fyet = 0;
71107+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
71108+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
71109+ grsec_alert_fyet++;
71110+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
71111+ grsec_alert_wtime = curr_secs;
71112+ grsec_alert_fyet++;
71113+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
71114+ return FLOODING;
71115+ }
71116+ else return FLOODING;
71117+
71118+set_fmt:
71119+#endif
71120+ memset(buf, 0, PAGE_SIZE);
71121+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
71122+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
71123+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71124+ } else if (current->signal->curr_ip) {
71125+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
71126+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
71127+ } else if (gr_acl_is_enabled()) {
71128+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
71129+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
71130+ } else {
71131+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
71132+ strcpy(buf, fmt);
71133+ }
71134+
71135+ return NO_FLOODING;
71136+}
71137+
71138+static void gr_log_middle(int audit, const char *msg, va_list ap)
71139+ __attribute__ ((format (printf, 2, 0)));
71140+
71141+static void gr_log_middle(int audit, const char *msg, va_list ap)
71142+{
71143+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71144+ unsigned int len = strlen(buf);
71145+
71146+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71147+
71148+ return;
71149+}
71150+
71151+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71152+ __attribute__ ((format (printf, 2, 3)));
71153+
71154+static void gr_log_middle_varargs(int audit, const char *msg, ...)
71155+{
71156+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71157+ unsigned int len = strlen(buf);
71158+ va_list ap;
71159+
71160+ va_start(ap, msg);
71161+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
71162+ va_end(ap);
71163+
71164+ return;
71165+}
71166+
71167+static void gr_log_end(int audit, int append_default)
71168+{
71169+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
71170+ if (append_default) {
71171+ struct task_struct *task = current;
71172+ struct task_struct *parent = task->real_parent;
71173+ const struct cred *cred = __task_cred(task);
71174+ const struct cred *pcred = __task_cred(parent);
71175+ unsigned int len = strlen(buf);
71176+
71177+ 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));
71178+ }
71179+
71180+ printk("%s\n", buf);
71181+
71182+ return;
71183+}
71184+
71185+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
71186+{
71187+ int logtype;
71188+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
71189+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
71190+ void *voidptr = NULL;
71191+ int num1 = 0, num2 = 0;
71192+ unsigned long ulong1 = 0, ulong2 = 0;
71193+ struct dentry *dentry = NULL;
71194+ struct vfsmount *mnt = NULL;
71195+ struct file *file = NULL;
71196+ struct task_struct *task = NULL;
71197+ struct vm_area_struct *vma = NULL;
71198+ const struct cred *cred, *pcred;
71199+ va_list ap;
71200+
71201+ BEGIN_LOCKS(audit);
71202+ logtype = gr_log_start(audit);
71203+ if (logtype == FLOODING) {
71204+ END_LOCKS(audit);
71205+ return;
71206+ }
71207+ va_start(ap, argtypes);
71208+ switch (argtypes) {
71209+ case GR_TTYSNIFF:
71210+ task = va_arg(ap, struct task_struct *);
71211+ 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));
71212+ break;
71213+ case GR_SYSCTL_HIDDEN:
71214+ str1 = va_arg(ap, char *);
71215+ gr_log_middle_varargs(audit, msg, result, str1);
71216+ break;
71217+ case GR_RBAC:
71218+ dentry = va_arg(ap, struct dentry *);
71219+ mnt = va_arg(ap, struct vfsmount *);
71220+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
71221+ break;
71222+ case GR_RBAC_STR:
71223+ dentry = va_arg(ap, struct dentry *);
71224+ mnt = va_arg(ap, struct vfsmount *);
71225+ str1 = va_arg(ap, char *);
71226+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
71227+ break;
71228+ case GR_STR_RBAC:
71229+ str1 = va_arg(ap, char *);
71230+ dentry = va_arg(ap, struct dentry *);
71231+ mnt = va_arg(ap, struct vfsmount *);
71232+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
71233+ break;
71234+ case GR_RBAC_MODE2:
71235+ dentry = va_arg(ap, struct dentry *);
71236+ mnt = va_arg(ap, struct vfsmount *);
71237+ str1 = va_arg(ap, char *);
71238+ str2 = va_arg(ap, char *);
71239+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
71240+ break;
71241+ case GR_RBAC_MODE3:
71242+ dentry = va_arg(ap, struct dentry *);
71243+ mnt = va_arg(ap, struct vfsmount *);
71244+ str1 = va_arg(ap, char *);
71245+ str2 = va_arg(ap, char *);
71246+ str3 = va_arg(ap, char *);
71247+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
71248+ break;
71249+ case GR_FILENAME:
71250+ dentry = va_arg(ap, struct dentry *);
71251+ mnt = va_arg(ap, struct vfsmount *);
71252+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
71253+ break;
71254+ case GR_STR_FILENAME:
71255+ str1 = va_arg(ap, char *);
71256+ dentry = va_arg(ap, struct dentry *);
71257+ mnt = va_arg(ap, struct vfsmount *);
71258+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
71259+ break;
71260+ case GR_FILENAME_STR:
71261+ dentry = va_arg(ap, struct dentry *);
71262+ mnt = va_arg(ap, struct vfsmount *);
71263+ str1 = va_arg(ap, char *);
71264+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
71265+ break;
71266+ case GR_FILENAME_TWO_INT:
71267+ dentry = va_arg(ap, struct dentry *);
71268+ mnt = va_arg(ap, struct vfsmount *);
71269+ num1 = va_arg(ap, int);
71270+ num2 = va_arg(ap, int);
71271+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
71272+ break;
71273+ case GR_FILENAME_TWO_INT_STR:
71274+ dentry = va_arg(ap, struct dentry *);
71275+ mnt = va_arg(ap, struct vfsmount *);
71276+ num1 = va_arg(ap, int);
71277+ num2 = va_arg(ap, int);
71278+ str1 = va_arg(ap, char *);
71279+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
71280+ break;
71281+ case GR_TEXTREL:
71282+ file = va_arg(ap, struct file *);
71283+ ulong1 = va_arg(ap, unsigned long);
71284+ ulong2 = va_arg(ap, unsigned long);
71285+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
71286+ break;
71287+ case GR_PTRACE:
71288+ task = va_arg(ap, struct task_struct *);
71289+ 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));
71290+ break;
71291+ case GR_RESOURCE:
71292+ task = va_arg(ap, struct task_struct *);
71293+ cred = __task_cred(task);
71294+ pcred = __task_cred(task->real_parent);
71295+ ulong1 = va_arg(ap, unsigned long);
71296+ str1 = va_arg(ap, char *);
71297+ ulong2 = va_arg(ap, unsigned long);
71298+ 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));
71299+ break;
71300+ case GR_CAP:
71301+ task = va_arg(ap, struct task_struct *);
71302+ cred = __task_cred(task);
71303+ pcred = __task_cred(task->real_parent);
71304+ str1 = va_arg(ap, char *);
71305+ 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));
71306+ break;
71307+ case GR_SIG:
71308+ str1 = va_arg(ap, char *);
71309+ voidptr = va_arg(ap, void *);
71310+ gr_log_middle_varargs(audit, msg, str1, voidptr);
71311+ break;
71312+ case GR_SIG2:
71313+ task = va_arg(ap, struct task_struct *);
71314+ cred = __task_cred(task);
71315+ pcred = __task_cred(task->real_parent);
71316+ num1 = va_arg(ap, int);
71317+ 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));
71318+ break;
71319+ case GR_CRASH1:
71320+ task = va_arg(ap, struct task_struct *);
71321+ cred = __task_cred(task);
71322+ pcred = __task_cred(task->real_parent);
71323+ ulong1 = va_arg(ap, unsigned long);
71324+ 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);
71325+ break;
71326+ case GR_CRASH2:
71327+ task = va_arg(ap, struct task_struct *);
71328+ cred = __task_cred(task);
71329+ pcred = __task_cred(task->real_parent);
71330+ ulong1 = va_arg(ap, unsigned long);
71331+ 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);
71332+ break;
71333+ case GR_RWXMAP:
71334+ file = va_arg(ap, struct file *);
71335+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
71336+ break;
71337+ case GR_RWXMAPVMA:
71338+ vma = va_arg(ap, struct vm_area_struct *);
71339+ if (vma->vm_file)
71340+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
71341+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
71342+ str1 = "<stack>";
71343+ else if (vma->vm_start <= current->mm->brk &&
71344+ vma->vm_end >= current->mm->start_brk)
71345+ str1 = "<heap>";
71346+ else
71347+ str1 = "<anonymous mapping>";
71348+ gr_log_middle_varargs(audit, msg, str1);
71349+ break;
71350+ case GR_PSACCT:
71351+ {
71352+ unsigned int wday, cday;
71353+ __u8 whr, chr;
71354+ __u8 wmin, cmin;
71355+ __u8 wsec, csec;
71356+ char cur_tty[64] = { 0 };
71357+ char parent_tty[64] = { 0 };
71358+
71359+ task = va_arg(ap, struct task_struct *);
71360+ wday = va_arg(ap, unsigned int);
71361+ cday = va_arg(ap, unsigned int);
71362+ whr = va_arg(ap, int);
71363+ chr = va_arg(ap, int);
71364+ wmin = va_arg(ap, int);
71365+ cmin = va_arg(ap, int);
71366+ wsec = va_arg(ap, int);
71367+ csec = va_arg(ap, int);
71368+ ulong1 = va_arg(ap, unsigned long);
71369+ cred = __task_cred(task);
71370+ pcred = __task_cred(task->real_parent);
71371+
71372+ 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));
71373+ }
71374+ break;
71375+ default:
71376+ gr_log_middle(audit, msg, ap);
71377+ }
71378+ va_end(ap);
71379+ // these don't need DEFAULTSECARGS printed on the end
71380+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
71381+ gr_log_end(audit, 0);
71382+ else
71383+ gr_log_end(audit, 1);
71384+ END_LOCKS(audit);
71385+}
71386diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
71387new file mode 100644
71388index 0000000..f536303
71389--- /dev/null
71390+++ b/grsecurity/grsec_mem.c
71391@@ -0,0 +1,40 @@
71392+#include <linux/kernel.h>
71393+#include <linux/sched.h>
71394+#include <linux/mm.h>
71395+#include <linux/mman.h>
71396+#include <linux/grinternal.h>
71397+
71398+void
71399+gr_handle_ioperm(void)
71400+{
71401+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
71402+ return;
71403+}
71404+
71405+void
71406+gr_handle_iopl(void)
71407+{
71408+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
71409+ return;
71410+}
71411+
71412+void
71413+gr_handle_mem_readwrite(u64 from, u64 to)
71414+{
71415+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
71416+ return;
71417+}
71418+
71419+void
71420+gr_handle_vm86(void)
71421+{
71422+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
71423+ return;
71424+}
71425+
71426+void
71427+gr_log_badprocpid(const char *entry)
71428+{
71429+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
71430+ return;
71431+}
71432diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
71433new file mode 100644
71434index 0000000..2131422
71435--- /dev/null
71436+++ b/grsecurity/grsec_mount.c
71437@@ -0,0 +1,62 @@
71438+#include <linux/kernel.h>
71439+#include <linux/sched.h>
71440+#include <linux/mount.h>
71441+#include <linux/grsecurity.h>
71442+#include <linux/grinternal.h>
71443+
71444+void
71445+gr_log_remount(const char *devname, const int retval)
71446+{
71447+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71448+ if (grsec_enable_mount && (retval >= 0))
71449+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
71450+#endif
71451+ return;
71452+}
71453+
71454+void
71455+gr_log_unmount(const char *devname, const int retval)
71456+{
71457+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71458+ if (grsec_enable_mount && (retval >= 0))
71459+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
71460+#endif
71461+ return;
71462+}
71463+
71464+void
71465+gr_log_mount(const char *from, const char *to, const int retval)
71466+{
71467+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71468+ if (grsec_enable_mount && (retval >= 0))
71469+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
71470+#endif
71471+ return;
71472+}
71473+
71474+int
71475+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
71476+{
71477+#ifdef CONFIG_GRKERNSEC_ROFS
71478+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
71479+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
71480+ return -EPERM;
71481+ } else
71482+ return 0;
71483+#endif
71484+ return 0;
71485+}
71486+
71487+int
71488+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
71489+{
71490+#ifdef CONFIG_GRKERNSEC_ROFS
71491+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
71492+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
71493+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
71494+ return -EPERM;
71495+ } else
71496+ return 0;
71497+#endif
71498+ return 0;
71499+}
71500diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
71501new file mode 100644
71502index 0000000..6ee9d50
71503--- /dev/null
71504+++ b/grsecurity/grsec_pax.c
71505@@ -0,0 +1,45 @@
71506+#include <linux/kernel.h>
71507+#include <linux/sched.h>
71508+#include <linux/mm.h>
71509+#include <linux/file.h>
71510+#include <linux/grinternal.h>
71511+#include <linux/grsecurity.h>
71512+
71513+void
71514+gr_log_textrel(struct vm_area_struct * vma)
71515+{
71516+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71517+ if (grsec_enable_log_rwxmaps)
71518+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
71519+#endif
71520+ return;
71521+}
71522+
71523+void gr_log_ptgnustack(struct file *file)
71524+{
71525+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71526+ if (grsec_enable_log_rwxmaps)
71527+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
71528+#endif
71529+ return;
71530+}
71531+
71532+void
71533+gr_log_rwxmmap(struct file *file)
71534+{
71535+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71536+ if (grsec_enable_log_rwxmaps)
71537+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
71538+#endif
71539+ return;
71540+}
71541+
71542+void
71543+gr_log_rwxmprotect(struct vm_area_struct *vma)
71544+{
71545+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71546+ if (grsec_enable_log_rwxmaps)
71547+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
71548+#endif
71549+ return;
71550+}
71551diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
71552new file mode 100644
71553index 0000000..f7f29aa
71554--- /dev/null
71555+++ b/grsecurity/grsec_ptrace.c
71556@@ -0,0 +1,30 @@
71557+#include <linux/kernel.h>
71558+#include <linux/sched.h>
71559+#include <linux/grinternal.h>
71560+#include <linux/security.h>
71561+
71562+void
71563+gr_audit_ptrace(struct task_struct *task)
71564+{
71565+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71566+ if (grsec_enable_audit_ptrace)
71567+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
71568+#endif
71569+ return;
71570+}
71571+
71572+int
71573+gr_ptrace_readexec(struct file *file, int unsafe_flags)
71574+{
71575+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71576+ const struct dentry *dentry = file->f_path.dentry;
71577+ const struct vfsmount *mnt = file->f_path.mnt;
71578+
71579+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
71580+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
71581+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
71582+ return -EACCES;
71583+ }
71584+#endif
71585+ return 0;
71586+}
71587diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
71588new file mode 100644
71589index 0000000..4e29cc7
71590--- /dev/null
71591+++ b/grsecurity/grsec_sig.c
71592@@ -0,0 +1,246 @@
71593+#include <linux/kernel.h>
71594+#include <linux/sched.h>
71595+#include <linux/fs.h>
71596+#include <linux/delay.h>
71597+#include <linux/grsecurity.h>
71598+#include <linux/grinternal.h>
71599+#include <linux/hardirq.h>
71600+
71601+char *signames[] = {
71602+ [SIGSEGV] = "Segmentation fault",
71603+ [SIGILL] = "Illegal instruction",
71604+ [SIGABRT] = "Abort",
71605+ [SIGBUS] = "Invalid alignment/Bus error"
71606+};
71607+
71608+void
71609+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
71610+{
71611+#ifdef CONFIG_GRKERNSEC_SIGNAL
71612+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
71613+ (sig == SIGABRT) || (sig == SIGBUS))) {
71614+ if (task_pid_nr(t) == task_pid_nr(current)) {
71615+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
71616+ } else {
71617+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
71618+ }
71619+ }
71620+#endif
71621+ return;
71622+}
71623+
71624+int
71625+gr_handle_signal(const struct task_struct *p, const int sig)
71626+{
71627+#ifdef CONFIG_GRKERNSEC
71628+ /* ignore the 0 signal for protected task checks */
71629+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
71630+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
71631+ return -EPERM;
71632+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
71633+ return -EPERM;
71634+ }
71635+#endif
71636+ return 0;
71637+}
71638+
71639+#ifdef CONFIG_GRKERNSEC
71640+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
71641+
71642+int gr_fake_force_sig(int sig, struct task_struct *t)
71643+{
71644+ unsigned long int flags;
71645+ int ret, blocked, ignored;
71646+ struct k_sigaction *action;
71647+
71648+ spin_lock_irqsave(&t->sighand->siglock, flags);
71649+ action = &t->sighand->action[sig-1];
71650+ ignored = action->sa.sa_handler == SIG_IGN;
71651+ blocked = sigismember(&t->blocked, sig);
71652+ if (blocked || ignored) {
71653+ action->sa.sa_handler = SIG_DFL;
71654+ if (blocked) {
71655+ sigdelset(&t->blocked, sig);
71656+ recalc_sigpending_and_wake(t);
71657+ }
71658+ }
71659+ if (action->sa.sa_handler == SIG_DFL)
71660+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
71661+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
71662+
71663+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
71664+
71665+ return ret;
71666+}
71667+#endif
71668+
71669+#ifdef CONFIG_GRKERNSEC_BRUTE
71670+#define GR_USER_BAN_TIME (15 * 60)
71671+#define GR_DAEMON_BRUTE_TIME (30 * 60)
71672+
71673+static int __get_dumpable(unsigned long mm_flags)
71674+{
71675+ int ret;
71676+
71677+ ret = mm_flags & MMF_DUMPABLE_MASK;
71678+ return (ret >= 2) ? 2 : ret;
71679+}
71680+#endif
71681+
71682+void gr_handle_brute_attach(unsigned long mm_flags)
71683+{
71684+#ifdef CONFIG_GRKERNSEC_BRUTE
71685+ struct task_struct *p = current;
71686+ kuid_t uid = GLOBAL_ROOT_UID;
71687+ int daemon = 0;
71688+
71689+ if (!grsec_enable_brute)
71690+ return;
71691+
71692+ rcu_read_lock();
71693+ read_lock(&tasklist_lock);
71694+ read_lock(&grsec_exec_file_lock);
71695+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
71696+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
71697+ p->real_parent->brute = 1;
71698+ daemon = 1;
71699+ } else {
71700+ const struct cred *cred = __task_cred(p), *cred2;
71701+ struct task_struct *tsk, *tsk2;
71702+
71703+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
71704+ struct user_struct *user;
71705+
71706+ uid = cred->uid;
71707+
71708+ /* this is put upon execution past expiration */
71709+ user = find_user(uid);
71710+ if (user == NULL)
71711+ goto unlock;
71712+ user->suid_banned = 1;
71713+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
71714+ if (user->suid_ban_expires == ~0UL)
71715+ user->suid_ban_expires--;
71716+
71717+ /* only kill other threads of the same binary, from the same user */
71718+ do_each_thread(tsk2, tsk) {
71719+ cred2 = __task_cred(tsk);
71720+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
71721+ gr_fake_force_sig(SIGKILL, tsk);
71722+ } while_each_thread(tsk2, tsk);
71723+ }
71724+ }
71725+unlock:
71726+ read_unlock(&grsec_exec_file_lock);
71727+ read_unlock(&tasklist_lock);
71728+ rcu_read_unlock();
71729+
71730+ if (gr_is_global_nonroot(uid))
71731+ 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);
71732+ else if (daemon)
71733+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
71734+
71735+#endif
71736+ return;
71737+}
71738+
71739+void gr_handle_brute_check(void)
71740+{
71741+#ifdef CONFIG_GRKERNSEC_BRUTE
71742+ struct task_struct *p = current;
71743+
71744+ if (unlikely(p->brute)) {
71745+ if (!grsec_enable_brute)
71746+ p->brute = 0;
71747+ else if (time_before(get_seconds(), p->brute_expires))
71748+ msleep(30 * 1000);
71749+ }
71750+#endif
71751+ return;
71752+}
71753+
71754+void gr_handle_kernel_exploit(void)
71755+{
71756+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71757+ const struct cred *cred;
71758+ struct task_struct *tsk, *tsk2;
71759+ struct user_struct *user;
71760+ kuid_t uid;
71761+
71762+ if (in_irq() || in_serving_softirq() || in_nmi())
71763+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
71764+
71765+ uid = current_uid();
71766+
71767+ if (gr_is_global_root(uid))
71768+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
71769+ else {
71770+ /* kill all the processes of this user, hold a reference
71771+ to their creds struct, and prevent them from creating
71772+ another process until system reset
71773+ */
71774+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
71775+ GR_GLOBAL_UID(uid));
71776+ /* we intentionally leak this ref */
71777+ user = get_uid(current->cred->user);
71778+ if (user)
71779+ user->kernel_banned = 1;
71780+
71781+ /* kill all processes of this user */
71782+ read_lock(&tasklist_lock);
71783+ do_each_thread(tsk2, tsk) {
71784+ cred = __task_cred(tsk);
71785+ if (uid_eq(cred->uid, uid))
71786+ gr_fake_force_sig(SIGKILL, tsk);
71787+ } while_each_thread(tsk2, tsk);
71788+ read_unlock(&tasklist_lock);
71789+ }
71790+#endif
71791+}
71792+
71793+#ifdef CONFIG_GRKERNSEC_BRUTE
71794+static bool suid_ban_expired(struct user_struct *user)
71795+{
71796+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
71797+ user->suid_banned = 0;
71798+ user->suid_ban_expires = 0;
71799+ free_uid(user);
71800+ return true;
71801+ }
71802+
71803+ return false;
71804+}
71805+#endif
71806+
71807+int gr_process_kernel_exec_ban(void)
71808+{
71809+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71810+ if (unlikely(current->cred->user->kernel_banned))
71811+ return -EPERM;
71812+#endif
71813+ return 0;
71814+}
71815+
71816+int gr_process_kernel_setuid_ban(struct user_struct *user)
71817+{
71818+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71819+ if (unlikely(user->kernel_banned))
71820+ gr_fake_force_sig(SIGKILL, current);
71821+#endif
71822+ return 0;
71823+}
71824+
71825+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
71826+{
71827+#ifdef CONFIG_GRKERNSEC_BRUTE
71828+ struct user_struct *user = current->cred->user;
71829+ if (unlikely(user->suid_banned)) {
71830+ if (suid_ban_expired(user))
71831+ return 0;
71832+ /* disallow execution of suid binaries only */
71833+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
71834+ return -EPERM;
71835+ }
71836+#endif
71837+ return 0;
71838+}
71839diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
71840new file mode 100644
71841index 0000000..4030d57
71842--- /dev/null
71843+++ b/grsecurity/grsec_sock.c
71844@@ -0,0 +1,244 @@
71845+#include <linux/kernel.h>
71846+#include <linux/module.h>
71847+#include <linux/sched.h>
71848+#include <linux/file.h>
71849+#include <linux/net.h>
71850+#include <linux/in.h>
71851+#include <linux/ip.h>
71852+#include <net/sock.h>
71853+#include <net/inet_sock.h>
71854+#include <linux/grsecurity.h>
71855+#include <linux/grinternal.h>
71856+#include <linux/gracl.h>
71857+
71858+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
71859+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
71860+
71861+EXPORT_SYMBOL(gr_search_udp_recvmsg);
71862+EXPORT_SYMBOL(gr_search_udp_sendmsg);
71863+
71864+#ifdef CONFIG_UNIX_MODULE
71865+EXPORT_SYMBOL(gr_acl_handle_unix);
71866+EXPORT_SYMBOL(gr_acl_handle_mknod);
71867+EXPORT_SYMBOL(gr_handle_chroot_unix);
71868+EXPORT_SYMBOL(gr_handle_create);
71869+#endif
71870+
71871+#ifdef CONFIG_GRKERNSEC
71872+#define gr_conn_table_size 32749
71873+struct conn_table_entry {
71874+ struct conn_table_entry *next;
71875+ struct signal_struct *sig;
71876+};
71877+
71878+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
71879+DEFINE_SPINLOCK(gr_conn_table_lock);
71880+
71881+extern const char * gr_socktype_to_name(unsigned char type);
71882+extern const char * gr_proto_to_name(unsigned char proto);
71883+extern const char * gr_sockfamily_to_name(unsigned char family);
71884+
71885+static __inline__ int
71886+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
71887+{
71888+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
71889+}
71890+
71891+static __inline__ int
71892+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
71893+ __u16 sport, __u16 dport)
71894+{
71895+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
71896+ sig->gr_sport == sport && sig->gr_dport == dport))
71897+ return 1;
71898+ else
71899+ return 0;
71900+}
71901+
71902+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
71903+{
71904+ struct conn_table_entry **match;
71905+ unsigned int index;
71906+
71907+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71908+ sig->gr_sport, sig->gr_dport,
71909+ gr_conn_table_size);
71910+
71911+ newent->sig = sig;
71912+
71913+ match = &gr_conn_table[index];
71914+ newent->next = *match;
71915+ *match = newent;
71916+
71917+ return;
71918+}
71919+
71920+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
71921+{
71922+ struct conn_table_entry *match, *last = NULL;
71923+ unsigned int index;
71924+
71925+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71926+ sig->gr_sport, sig->gr_dport,
71927+ gr_conn_table_size);
71928+
71929+ match = gr_conn_table[index];
71930+ while (match && !conn_match(match->sig,
71931+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
71932+ sig->gr_dport)) {
71933+ last = match;
71934+ match = match->next;
71935+ }
71936+
71937+ if (match) {
71938+ if (last)
71939+ last->next = match->next;
71940+ else
71941+ gr_conn_table[index] = NULL;
71942+ kfree(match);
71943+ }
71944+
71945+ return;
71946+}
71947+
71948+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
71949+ __u16 sport, __u16 dport)
71950+{
71951+ struct conn_table_entry *match;
71952+ unsigned int index;
71953+
71954+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
71955+
71956+ match = gr_conn_table[index];
71957+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
71958+ match = match->next;
71959+
71960+ if (match)
71961+ return match->sig;
71962+ else
71963+ return NULL;
71964+}
71965+
71966+#endif
71967+
71968+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
71969+{
71970+#ifdef CONFIG_GRKERNSEC
71971+ struct signal_struct *sig = task->signal;
71972+ struct conn_table_entry *newent;
71973+
71974+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
71975+ if (newent == NULL)
71976+ return;
71977+ /* no bh lock needed since we are called with bh disabled */
71978+ spin_lock(&gr_conn_table_lock);
71979+ gr_del_task_from_ip_table_nolock(sig);
71980+ sig->gr_saddr = inet->inet_rcv_saddr;
71981+ sig->gr_daddr = inet->inet_daddr;
71982+ sig->gr_sport = inet->inet_sport;
71983+ sig->gr_dport = inet->inet_dport;
71984+ gr_add_to_task_ip_table_nolock(sig, newent);
71985+ spin_unlock(&gr_conn_table_lock);
71986+#endif
71987+ return;
71988+}
71989+
71990+void gr_del_task_from_ip_table(struct task_struct *task)
71991+{
71992+#ifdef CONFIG_GRKERNSEC
71993+ spin_lock_bh(&gr_conn_table_lock);
71994+ gr_del_task_from_ip_table_nolock(task->signal);
71995+ spin_unlock_bh(&gr_conn_table_lock);
71996+#endif
71997+ return;
71998+}
71999+
72000+void
72001+gr_attach_curr_ip(const struct sock *sk)
72002+{
72003+#ifdef CONFIG_GRKERNSEC
72004+ struct signal_struct *p, *set;
72005+ const struct inet_sock *inet = inet_sk(sk);
72006+
72007+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
72008+ return;
72009+
72010+ set = current->signal;
72011+
72012+ spin_lock_bh(&gr_conn_table_lock);
72013+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
72014+ inet->inet_dport, inet->inet_sport);
72015+ if (unlikely(p != NULL)) {
72016+ set->curr_ip = p->curr_ip;
72017+ set->used_accept = 1;
72018+ gr_del_task_from_ip_table_nolock(p);
72019+ spin_unlock_bh(&gr_conn_table_lock);
72020+ return;
72021+ }
72022+ spin_unlock_bh(&gr_conn_table_lock);
72023+
72024+ set->curr_ip = inet->inet_daddr;
72025+ set->used_accept = 1;
72026+#endif
72027+ return;
72028+}
72029+
72030+int
72031+gr_handle_sock_all(const int family, const int type, const int protocol)
72032+{
72033+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72034+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
72035+ (family != AF_UNIX)) {
72036+ if (family == AF_INET)
72037+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
72038+ else
72039+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
72040+ return -EACCES;
72041+ }
72042+#endif
72043+ return 0;
72044+}
72045+
72046+int
72047+gr_handle_sock_server(const struct sockaddr *sck)
72048+{
72049+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72050+ if (grsec_enable_socket_server &&
72051+ in_group_p(grsec_socket_server_gid) &&
72052+ sck && (sck->sa_family != AF_UNIX) &&
72053+ (sck->sa_family != AF_LOCAL)) {
72054+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72055+ return -EACCES;
72056+ }
72057+#endif
72058+ return 0;
72059+}
72060+
72061+int
72062+gr_handle_sock_server_other(const struct sock *sck)
72063+{
72064+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72065+ if (grsec_enable_socket_server &&
72066+ in_group_p(grsec_socket_server_gid) &&
72067+ sck && (sck->sk_family != AF_UNIX) &&
72068+ (sck->sk_family != AF_LOCAL)) {
72069+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
72070+ return -EACCES;
72071+ }
72072+#endif
72073+ return 0;
72074+}
72075+
72076+int
72077+gr_handle_sock_client(const struct sockaddr *sck)
72078+{
72079+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72080+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
72081+ sck && (sck->sa_family != AF_UNIX) &&
72082+ (sck->sa_family != AF_LOCAL)) {
72083+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
72084+ return -EACCES;
72085+ }
72086+#endif
72087+ return 0;
72088+}
72089diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
72090new file mode 100644
72091index 0000000..a147ae7
72092--- /dev/null
72093+++ b/grsecurity/grsec_sysctl.c
72094@@ -0,0 +1,470 @@
72095+#include <linux/kernel.h>
72096+#include <linux/sched.h>
72097+#include <linux/sysctl.h>
72098+#include <linux/grsecurity.h>
72099+#include <linux/grinternal.h>
72100+
72101+int
72102+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
72103+{
72104+#ifdef CONFIG_GRKERNSEC_SYSCTL
72105+ if (dirname == NULL || name == NULL)
72106+ return 0;
72107+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
72108+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
72109+ return -EACCES;
72110+ }
72111+#endif
72112+ return 0;
72113+}
72114+
72115+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
72116+static int __maybe_unused __read_only one = 1;
72117+#endif
72118+
72119+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
72120+ defined(CONFIG_GRKERNSEC_DENYUSB)
72121+struct ctl_table grsecurity_table[] = {
72122+#ifdef CONFIG_GRKERNSEC_SYSCTL
72123+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
72124+#ifdef CONFIG_GRKERNSEC_IO
72125+ {
72126+ .procname = "disable_priv_io",
72127+ .data = &grsec_disable_privio,
72128+ .maxlen = sizeof(int),
72129+ .mode = 0600,
72130+ .proc_handler = &proc_dointvec,
72131+ },
72132+#endif
72133+#endif
72134+#ifdef CONFIG_GRKERNSEC_LINK
72135+ {
72136+ .procname = "linking_restrictions",
72137+ .data = &grsec_enable_link,
72138+ .maxlen = sizeof(int),
72139+ .mode = 0600,
72140+ .proc_handler = &proc_dointvec,
72141+ },
72142+#endif
72143+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
72144+ {
72145+ .procname = "enforce_symlinksifowner",
72146+ .data = &grsec_enable_symlinkown,
72147+ .maxlen = sizeof(int),
72148+ .mode = 0600,
72149+ .proc_handler = &proc_dointvec,
72150+ },
72151+ {
72152+ .procname = "symlinkown_gid",
72153+ .data = &grsec_symlinkown_gid,
72154+ .maxlen = sizeof(int),
72155+ .mode = 0600,
72156+ .proc_handler = &proc_dointvec,
72157+ },
72158+#endif
72159+#ifdef CONFIG_GRKERNSEC_BRUTE
72160+ {
72161+ .procname = "deter_bruteforce",
72162+ .data = &grsec_enable_brute,
72163+ .maxlen = sizeof(int),
72164+ .mode = 0600,
72165+ .proc_handler = &proc_dointvec,
72166+ },
72167+#endif
72168+#ifdef CONFIG_GRKERNSEC_FIFO
72169+ {
72170+ .procname = "fifo_restrictions",
72171+ .data = &grsec_enable_fifo,
72172+ .maxlen = sizeof(int),
72173+ .mode = 0600,
72174+ .proc_handler = &proc_dointvec,
72175+ },
72176+#endif
72177+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
72178+ {
72179+ .procname = "ptrace_readexec",
72180+ .data = &grsec_enable_ptrace_readexec,
72181+ .maxlen = sizeof(int),
72182+ .mode = 0600,
72183+ .proc_handler = &proc_dointvec,
72184+ },
72185+#endif
72186+#ifdef CONFIG_GRKERNSEC_SETXID
72187+ {
72188+ .procname = "consistent_setxid",
72189+ .data = &grsec_enable_setxid,
72190+ .maxlen = sizeof(int),
72191+ .mode = 0600,
72192+ .proc_handler = &proc_dointvec,
72193+ },
72194+#endif
72195+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
72196+ {
72197+ .procname = "ip_blackhole",
72198+ .data = &grsec_enable_blackhole,
72199+ .maxlen = sizeof(int),
72200+ .mode = 0600,
72201+ .proc_handler = &proc_dointvec,
72202+ },
72203+ {
72204+ .procname = "lastack_retries",
72205+ .data = &grsec_lastack_retries,
72206+ .maxlen = sizeof(int),
72207+ .mode = 0600,
72208+ .proc_handler = &proc_dointvec,
72209+ },
72210+#endif
72211+#ifdef CONFIG_GRKERNSEC_EXECLOG
72212+ {
72213+ .procname = "exec_logging",
72214+ .data = &grsec_enable_execlog,
72215+ .maxlen = sizeof(int),
72216+ .mode = 0600,
72217+ .proc_handler = &proc_dointvec,
72218+ },
72219+#endif
72220+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
72221+ {
72222+ .procname = "rwxmap_logging",
72223+ .data = &grsec_enable_log_rwxmaps,
72224+ .maxlen = sizeof(int),
72225+ .mode = 0600,
72226+ .proc_handler = &proc_dointvec,
72227+ },
72228+#endif
72229+#ifdef CONFIG_GRKERNSEC_SIGNAL
72230+ {
72231+ .procname = "signal_logging",
72232+ .data = &grsec_enable_signal,
72233+ .maxlen = sizeof(int),
72234+ .mode = 0600,
72235+ .proc_handler = &proc_dointvec,
72236+ },
72237+#endif
72238+#ifdef CONFIG_GRKERNSEC_FORKFAIL
72239+ {
72240+ .procname = "forkfail_logging",
72241+ .data = &grsec_enable_forkfail,
72242+ .maxlen = sizeof(int),
72243+ .mode = 0600,
72244+ .proc_handler = &proc_dointvec,
72245+ },
72246+#endif
72247+#ifdef CONFIG_GRKERNSEC_TIME
72248+ {
72249+ .procname = "timechange_logging",
72250+ .data = &grsec_enable_time,
72251+ .maxlen = sizeof(int),
72252+ .mode = 0600,
72253+ .proc_handler = &proc_dointvec,
72254+ },
72255+#endif
72256+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72257+ {
72258+ .procname = "chroot_deny_shmat",
72259+ .data = &grsec_enable_chroot_shmat,
72260+ .maxlen = sizeof(int),
72261+ .mode = 0600,
72262+ .proc_handler = &proc_dointvec,
72263+ },
72264+#endif
72265+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72266+ {
72267+ .procname = "chroot_deny_unix",
72268+ .data = &grsec_enable_chroot_unix,
72269+ .maxlen = sizeof(int),
72270+ .mode = 0600,
72271+ .proc_handler = &proc_dointvec,
72272+ },
72273+#endif
72274+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72275+ {
72276+ .procname = "chroot_deny_mount",
72277+ .data = &grsec_enable_chroot_mount,
72278+ .maxlen = sizeof(int),
72279+ .mode = 0600,
72280+ .proc_handler = &proc_dointvec,
72281+ },
72282+#endif
72283+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72284+ {
72285+ .procname = "chroot_deny_fchdir",
72286+ .data = &grsec_enable_chroot_fchdir,
72287+ .maxlen = sizeof(int),
72288+ .mode = 0600,
72289+ .proc_handler = &proc_dointvec,
72290+ },
72291+#endif
72292+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72293+ {
72294+ .procname = "chroot_deny_chroot",
72295+ .data = &grsec_enable_chroot_double,
72296+ .maxlen = sizeof(int),
72297+ .mode = 0600,
72298+ .proc_handler = &proc_dointvec,
72299+ },
72300+#endif
72301+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72302+ {
72303+ .procname = "chroot_deny_pivot",
72304+ .data = &grsec_enable_chroot_pivot,
72305+ .maxlen = sizeof(int),
72306+ .mode = 0600,
72307+ .proc_handler = &proc_dointvec,
72308+ },
72309+#endif
72310+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72311+ {
72312+ .procname = "chroot_enforce_chdir",
72313+ .data = &grsec_enable_chroot_chdir,
72314+ .maxlen = sizeof(int),
72315+ .mode = 0600,
72316+ .proc_handler = &proc_dointvec,
72317+ },
72318+#endif
72319+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72320+ {
72321+ .procname = "chroot_deny_chmod",
72322+ .data = &grsec_enable_chroot_chmod,
72323+ .maxlen = sizeof(int),
72324+ .mode = 0600,
72325+ .proc_handler = &proc_dointvec,
72326+ },
72327+#endif
72328+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72329+ {
72330+ .procname = "chroot_deny_mknod",
72331+ .data = &grsec_enable_chroot_mknod,
72332+ .maxlen = sizeof(int),
72333+ .mode = 0600,
72334+ .proc_handler = &proc_dointvec,
72335+ },
72336+#endif
72337+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72338+ {
72339+ .procname = "chroot_restrict_nice",
72340+ .data = &grsec_enable_chroot_nice,
72341+ .maxlen = sizeof(int),
72342+ .mode = 0600,
72343+ .proc_handler = &proc_dointvec,
72344+ },
72345+#endif
72346+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72347+ {
72348+ .procname = "chroot_execlog",
72349+ .data = &grsec_enable_chroot_execlog,
72350+ .maxlen = sizeof(int),
72351+ .mode = 0600,
72352+ .proc_handler = &proc_dointvec,
72353+ },
72354+#endif
72355+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72356+ {
72357+ .procname = "chroot_caps",
72358+ .data = &grsec_enable_chroot_caps,
72359+ .maxlen = sizeof(int),
72360+ .mode = 0600,
72361+ .proc_handler = &proc_dointvec,
72362+ },
72363+#endif
72364+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72365+ {
72366+ .procname = "chroot_deny_sysctl",
72367+ .data = &grsec_enable_chroot_sysctl,
72368+ .maxlen = sizeof(int),
72369+ .mode = 0600,
72370+ .proc_handler = &proc_dointvec,
72371+ },
72372+#endif
72373+#ifdef CONFIG_GRKERNSEC_TPE
72374+ {
72375+ .procname = "tpe",
72376+ .data = &grsec_enable_tpe,
72377+ .maxlen = sizeof(int),
72378+ .mode = 0600,
72379+ .proc_handler = &proc_dointvec,
72380+ },
72381+ {
72382+ .procname = "tpe_gid",
72383+ .data = &grsec_tpe_gid,
72384+ .maxlen = sizeof(int),
72385+ .mode = 0600,
72386+ .proc_handler = &proc_dointvec,
72387+ },
72388+#endif
72389+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72390+ {
72391+ .procname = "tpe_invert",
72392+ .data = &grsec_enable_tpe_invert,
72393+ .maxlen = sizeof(int),
72394+ .mode = 0600,
72395+ .proc_handler = &proc_dointvec,
72396+ },
72397+#endif
72398+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72399+ {
72400+ .procname = "tpe_restrict_all",
72401+ .data = &grsec_enable_tpe_all,
72402+ .maxlen = sizeof(int),
72403+ .mode = 0600,
72404+ .proc_handler = &proc_dointvec,
72405+ },
72406+#endif
72407+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72408+ {
72409+ .procname = "socket_all",
72410+ .data = &grsec_enable_socket_all,
72411+ .maxlen = sizeof(int),
72412+ .mode = 0600,
72413+ .proc_handler = &proc_dointvec,
72414+ },
72415+ {
72416+ .procname = "socket_all_gid",
72417+ .data = &grsec_socket_all_gid,
72418+ .maxlen = sizeof(int),
72419+ .mode = 0600,
72420+ .proc_handler = &proc_dointvec,
72421+ },
72422+#endif
72423+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72424+ {
72425+ .procname = "socket_client",
72426+ .data = &grsec_enable_socket_client,
72427+ .maxlen = sizeof(int),
72428+ .mode = 0600,
72429+ .proc_handler = &proc_dointvec,
72430+ },
72431+ {
72432+ .procname = "socket_client_gid",
72433+ .data = &grsec_socket_client_gid,
72434+ .maxlen = sizeof(int),
72435+ .mode = 0600,
72436+ .proc_handler = &proc_dointvec,
72437+ },
72438+#endif
72439+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72440+ {
72441+ .procname = "socket_server",
72442+ .data = &grsec_enable_socket_server,
72443+ .maxlen = sizeof(int),
72444+ .mode = 0600,
72445+ .proc_handler = &proc_dointvec,
72446+ },
72447+ {
72448+ .procname = "socket_server_gid",
72449+ .data = &grsec_socket_server_gid,
72450+ .maxlen = sizeof(int),
72451+ .mode = 0600,
72452+ .proc_handler = &proc_dointvec,
72453+ },
72454+#endif
72455+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
72456+ {
72457+ .procname = "audit_group",
72458+ .data = &grsec_enable_group,
72459+ .maxlen = sizeof(int),
72460+ .mode = 0600,
72461+ .proc_handler = &proc_dointvec,
72462+ },
72463+ {
72464+ .procname = "audit_gid",
72465+ .data = &grsec_audit_gid,
72466+ .maxlen = sizeof(int),
72467+ .mode = 0600,
72468+ .proc_handler = &proc_dointvec,
72469+ },
72470+#endif
72471+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72472+ {
72473+ .procname = "audit_chdir",
72474+ .data = &grsec_enable_chdir,
72475+ .maxlen = sizeof(int),
72476+ .mode = 0600,
72477+ .proc_handler = &proc_dointvec,
72478+ },
72479+#endif
72480+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72481+ {
72482+ .procname = "audit_mount",
72483+ .data = &grsec_enable_mount,
72484+ .maxlen = sizeof(int),
72485+ .mode = 0600,
72486+ .proc_handler = &proc_dointvec,
72487+ },
72488+#endif
72489+#ifdef CONFIG_GRKERNSEC_DMESG
72490+ {
72491+ .procname = "dmesg",
72492+ .data = &grsec_enable_dmesg,
72493+ .maxlen = sizeof(int),
72494+ .mode = 0600,
72495+ .proc_handler = &proc_dointvec,
72496+ },
72497+#endif
72498+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72499+ {
72500+ .procname = "chroot_findtask",
72501+ .data = &grsec_enable_chroot_findtask,
72502+ .maxlen = sizeof(int),
72503+ .mode = 0600,
72504+ .proc_handler = &proc_dointvec,
72505+ },
72506+#endif
72507+#ifdef CONFIG_GRKERNSEC_RESLOG
72508+ {
72509+ .procname = "resource_logging",
72510+ .data = &grsec_resource_logging,
72511+ .maxlen = sizeof(int),
72512+ .mode = 0600,
72513+ .proc_handler = &proc_dointvec,
72514+ },
72515+#endif
72516+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72517+ {
72518+ .procname = "audit_ptrace",
72519+ .data = &grsec_enable_audit_ptrace,
72520+ .maxlen = sizeof(int),
72521+ .mode = 0600,
72522+ .proc_handler = &proc_dointvec,
72523+ },
72524+#endif
72525+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72526+ {
72527+ .procname = "harden_ptrace",
72528+ .data = &grsec_enable_harden_ptrace,
72529+ .maxlen = sizeof(int),
72530+ .mode = 0600,
72531+ .proc_handler = &proc_dointvec,
72532+ },
72533+#endif
72534+ {
72535+ .procname = "grsec_lock",
72536+ .data = &grsec_lock,
72537+ .maxlen = sizeof(int),
72538+ .mode = 0600,
72539+ .proc_handler = &proc_dointvec,
72540+ },
72541+#endif
72542+#ifdef CONFIG_GRKERNSEC_ROFS
72543+ {
72544+ .procname = "romount_protect",
72545+ .data = &grsec_enable_rofs,
72546+ .maxlen = sizeof(int),
72547+ .mode = 0600,
72548+ .proc_handler = &proc_dointvec_minmax,
72549+ .extra1 = &one,
72550+ .extra2 = &one,
72551+ },
72552+#endif
72553+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
72554+ {
72555+ .procname = "deny_new_usb",
72556+ .data = &grsec_deny_new_usb,
72557+ .maxlen = sizeof(int),
72558+ .mode = 0600,
72559+ .proc_handler = &proc_dointvec,
72560+ },
72561+#endif
72562+ { }
72563+};
72564+#endif
72565diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
72566new file mode 100644
72567index 0000000..0dc13c3
72568--- /dev/null
72569+++ b/grsecurity/grsec_time.c
72570@@ -0,0 +1,16 @@
72571+#include <linux/kernel.h>
72572+#include <linux/sched.h>
72573+#include <linux/grinternal.h>
72574+#include <linux/module.h>
72575+
72576+void
72577+gr_log_timechange(void)
72578+{
72579+#ifdef CONFIG_GRKERNSEC_TIME
72580+ if (grsec_enable_time)
72581+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
72582+#endif
72583+ return;
72584+}
72585+
72586+EXPORT_SYMBOL(gr_log_timechange);
72587diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
72588new file mode 100644
72589index 0000000..ee57dcf
72590--- /dev/null
72591+++ b/grsecurity/grsec_tpe.c
72592@@ -0,0 +1,73 @@
72593+#include <linux/kernel.h>
72594+#include <linux/sched.h>
72595+#include <linux/file.h>
72596+#include <linux/fs.h>
72597+#include <linux/grinternal.h>
72598+
72599+extern int gr_acl_tpe_check(void);
72600+
72601+int
72602+gr_tpe_allow(const struct file *file)
72603+{
72604+#ifdef CONFIG_GRKERNSEC
72605+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
72606+ const struct cred *cred = current_cred();
72607+ char *msg = NULL;
72608+ char *msg2 = NULL;
72609+
72610+ // never restrict root
72611+ if (gr_is_global_root(cred->uid))
72612+ return 1;
72613+
72614+ if (grsec_enable_tpe) {
72615+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72616+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
72617+ msg = "not being in trusted group";
72618+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
72619+ msg = "being in untrusted group";
72620+#else
72621+ if (in_group_p(grsec_tpe_gid))
72622+ msg = "being in untrusted group";
72623+#endif
72624+ }
72625+ if (!msg && gr_acl_tpe_check())
72626+ msg = "being in untrusted role";
72627+
72628+ // not in any affected group/role
72629+ if (!msg)
72630+ goto next_check;
72631+
72632+ if (gr_is_global_nonroot(inode->i_uid))
72633+ msg2 = "file in non-root-owned directory";
72634+ else if (inode->i_mode & S_IWOTH)
72635+ msg2 = "file in world-writable directory";
72636+ else if (inode->i_mode & S_IWGRP)
72637+ msg2 = "file in group-writable directory";
72638+
72639+ if (msg && msg2) {
72640+ char fullmsg[70] = {0};
72641+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
72642+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
72643+ return 0;
72644+ }
72645+ msg = NULL;
72646+next_check:
72647+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72648+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
72649+ return 1;
72650+
72651+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
72652+ msg = "directory not owned by user";
72653+ else if (inode->i_mode & S_IWOTH)
72654+ msg = "file in world-writable directory";
72655+ else if (inode->i_mode & S_IWGRP)
72656+ msg = "file in group-writable directory";
72657+
72658+ if (msg) {
72659+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
72660+ return 0;
72661+ }
72662+#endif
72663+#endif
72664+ return 1;
72665+}
72666diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
72667new file mode 100644
72668index 0000000..ae02d8e
72669--- /dev/null
72670+++ b/grsecurity/grsec_usb.c
72671@@ -0,0 +1,15 @@
72672+#include <linux/kernel.h>
72673+#include <linux/grinternal.h>
72674+#include <linux/module.h>
72675+
72676+int gr_handle_new_usb(void)
72677+{
72678+#ifdef CONFIG_GRKERNSEC_DENYUSB
72679+ if (grsec_deny_new_usb) {
72680+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
72681+ return 1;
72682+ }
72683+#endif
72684+ return 0;
72685+}
72686+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
72687diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
72688new file mode 100644
72689index 0000000..9f7b1ac
72690--- /dev/null
72691+++ b/grsecurity/grsum.c
72692@@ -0,0 +1,61 @@
72693+#include <linux/err.h>
72694+#include <linux/kernel.h>
72695+#include <linux/sched.h>
72696+#include <linux/mm.h>
72697+#include <linux/scatterlist.h>
72698+#include <linux/crypto.h>
72699+#include <linux/gracl.h>
72700+
72701+
72702+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
72703+#error "crypto and sha256 must be built into the kernel"
72704+#endif
72705+
72706+int
72707+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
72708+{
72709+ char *p;
72710+ struct crypto_hash *tfm;
72711+ struct hash_desc desc;
72712+ struct scatterlist sg;
72713+ unsigned char temp_sum[GR_SHA_LEN];
72714+ volatile int retval = 0;
72715+ volatile int dummy = 0;
72716+ unsigned int i;
72717+
72718+ sg_init_table(&sg, 1);
72719+
72720+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
72721+ if (IS_ERR(tfm)) {
72722+ /* should never happen, since sha256 should be built in */
72723+ return 1;
72724+ }
72725+
72726+ desc.tfm = tfm;
72727+ desc.flags = 0;
72728+
72729+ crypto_hash_init(&desc);
72730+
72731+ p = salt;
72732+ sg_set_buf(&sg, p, GR_SALT_LEN);
72733+ crypto_hash_update(&desc, &sg, sg.length);
72734+
72735+ p = entry->pw;
72736+ sg_set_buf(&sg, p, strlen(p));
72737+
72738+ crypto_hash_update(&desc, &sg, sg.length);
72739+
72740+ crypto_hash_final(&desc, temp_sum);
72741+
72742+ memset(entry->pw, 0, GR_PW_LEN);
72743+
72744+ for (i = 0; i < GR_SHA_LEN; i++)
72745+ if (sum[i] != temp_sum[i])
72746+ retval = 1;
72747+ else
72748+ dummy = 1; // waste a cycle
72749+
72750+ crypto_free_hash(tfm);
72751+
72752+ return retval;
72753+}
72754diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
72755index 77ff547..181834f 100644
72756--- a/include/asm-generic/4level-fixup.h
72757+++ b/include/asm-generic/4level-fixup.h
72758@@ -13,8 +13,10 @@
72759 #define pmd_alloc(mm, pud, address) \
72760 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
72761 NULL: pmd_offset(pud, address))
72762+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
72763
72764 #define pud_alloc(mm, pgd, address) (pgd)
72765+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
72766 #define pud_offset(pgd, start) (pgd)
72767 #define pud_none(pud) 0
72768 #define pud_bad(pud) 0
72769diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
72770index b7babf0..04ad282 100644
72771--- a/include/asm-generic/atomic-long.h
72772+++ b/include/asm-generic/atomic-long.h
72773@@ -22,6 +22,12 @@
72774
72775 typedef atomic64_t atomic_long_t;
72776
72777+#ifdef CONFIG_PAX_REFCOUNT
72778+typedef atomic64_unchecked_t atomic_long_unchecked_t;
72779+#else
72780+typedef atomic64_t atomic_long_unchecked_t;
72781+#endif
72782+
72783 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
72784
72785 static inline long atomic_long_read(atomic_long_t *l)
72786@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72787 return (long)atomic64_read(v);
72788 }
72789
72790+#ifdef CONFIG_PAX_REFCOUNT
72791+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72792+{
72793+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72794+
72795+ return (long)atomic64_read_unchecked(v);
72796+}
72797+#endif
72798+
72799 static inline void atomic_long_set(atomic_long_t *l, long i)
72800 {
72801 atomic64_t *v = (atomic64_t *)l;
72802@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72803 atomic64_set(v, i);
72804 }
72805
72806+#ifdef CONFIG_PAX_REFCOUNT
72807+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72808+{
72809+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72810+
72811+ atomic64_set_unchecked(v, i);
72812+}
72813+#endif
72814+
72815 static inline void atomic_long_inc(atomic_long_t *l)
72816 {
72817 atomic64_t *v = (atomic64_t *)l;
72818@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72819 atomic64_inc(v);
72820 }
72821
72822+#ifdef CONFIG_PAX_REFCOUNT
72823+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72824+{
72825+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72826+
72827+ atomic64_inc_unchecked(v);
72828+}
72829+#endif
72830+
72831 static inline void atomic_long_dec(atomic_long_t *l)
72832 {
72833 atomic64_t *v = (atomic64_t *)l;
72834@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
72835 atomic64_dec(v);
72836 }
72837
72838+#ifdef CONFIG_PAX_REFCOUNT
72839+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
72840+{
72841+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72842+
72843+ atomic64_dec_unchecked(v);
72844+}
72845+#endif
72846+
72847 static inline void atomic_long_add(long i, atomic_long_t *l)
72848 {
72849 atomic64_t *v = (atomic64_t *)l;
72850@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
72851 atomic64_add(i, v);
72852 }
72853
72854+#ifdef CONFIG_PAX_REFCOUNT
72855+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
72856+{
72857+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72858+
72859+ atomic64_add_unchecked(i, v);
72860+}
72861+#endif
72862+
72863 static inline void atomic_long_sub(long i, atomic_long_t *l)
72864 {
72865 atomic64_t *v = (atomic64_t *)l;
72866@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
72867 atomic64_sub(i, v);
72868 }
72869
72870+#ifdef CONFIG_PAX_REFCOUNT
72871+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
72872+{
72873+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72874+
72875+ atomic64_sub_unchecked(i, v);
72876+}
72877+#endif
72878+
72879 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
72880 {
72881 atomic64_t *v = (atomic64_t *)l;
72882@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
72883 return (long)atomic64_add_return(i, v);
72884 }
72885
72886+#ifdef CONFIG_PAX_REFCOUNT
72887+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
72888+{
72889+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72890+
72891+ return (long)atomic64_add_return_unchecked(i, v);
72892+}
72893+#endif
72894+
72895 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
72896 {
72897 atomic64_t *v = (atomic64_t *)l;
72898@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
72899 return (long)atomic64_inc_return(v);
72900 }
72901
72902+#ifdef CONFIG_PAX_REFCOUNT
72903+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
72904+{
72905+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72906+
72907+ return (long)atomic64_inc_return_unchecked(v);
72908+}
72909+#endif
72910+
72911 static inline long atomic_long_dec_return(atomic_long_t *l)
72912 {
72913 atomic64_t *v = (atomic64_t *)l;
72914@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
72915
72916 typedef atomic_t atomic_long_t;
72917
72918+#ifdef CONFIG_PAX_REFCOUNT
72919+typedef atomic_unchecked_t atomic_long_unchecked_t;
72920+#else
72921+typedef atomic_t atomic_long_unchecked_t;
72922+#endif
72923+
72924 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
72925 static inline long atomic_long_read(atomic_long_t *l)
72926 {
72927@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72928 return (long)atomic_read(v);
72929 }
72930
72931+#ifdef CONFIG_PAX_REFCOUNT
72932+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72933+{
72934+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72935+
72936+ return (long)atomic_read_unchecked(v);
72937+}
72938+#endif
72939+
72940 static inline void atomic_long_set(atomic_long_t *l, long i)
72941 {
72942 atomic_t *v = (atomic_t *)l;
72943@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72944 atomic_set(v, i);
72945 }
72946
72947+#ifdef CONFIG_PAX_REFCOUNT
72948+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72949+{
72950+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72951+
72952+ atomic_set_unchecked(v, i);
72953+}
72954+#endif
72955+
72956 static inline void atomic_long_inc(atomic_long_t *l)
72957 {
72958 atomic_t *v = (atomic_t *)l;
72959@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72960 atomic_inc(v);
72961 }
72962
72963+#ifdef CONFIG_PAX_REFCOUNT
72964+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72965+{
72966+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72967+
72968+ atomic_inc_unchecked(v);
72969+}
72970+#endif
72971+
72972 static inline void atomic_long_dec(atomic_long_t *l)
72973 {
72974 atomic_t *v = (atomic_t *)l;
72975@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
72976 atomic_dec(v);
72977 }
72978
72979+#ifdef CONFIG_PAX_REFCOUNT
72980+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
72981+{
72982+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72983+
72984+ atomic_dec_unchecked(v);
72985+}
72986+#endif
72987+
72988 static inline void atomic_long_add(long i, atomic_long_t *l)
72989 {
72990 atomic_t *v = (atomic_t *)l;
72991@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
72992 atomic_add(i, v);
72993 }
72994
72995+#ifdef CONFIG_PAX_REFCOUNT
72996+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
72997+{
72998+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72999+
73000+ atomic_add_unchecked(i, v);
73001+}
73002+#endif
73003+
73004 static inline void atomic_long_sub(long i, atomic_long_t *l)
73005 {
73006 atomic_t *v = (atomic_t *)l;
73007@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
73008 atomic_sub(i, v);
73009 }
73010
73011+#ifdef CONFIG_PAX_REFCOUNT
73012+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
73013+{
73014+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73015+
73016+ atomic_sub_unchecked(i, v);
73017+}
73018+#endif
73019+
73020 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
73021 {
73022 atomic_t *v = (atomic_t *)l;
73023@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
73024 return (long)atomic_add_return(i, v);
73025 }
73026
73027+#ifdef CONFIG_PAX_REFCOUNT
73028+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
73029+{
73030+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73031+
73032+ return (long)atomic_add_return_unchecked(i, v);
73033+}
73034+
73035+#endif
73036+
73037 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
73038 {
73039 atomic_t *v = (atomic_t *)l;
73040@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
73041 return (long)atomic_inc_return(v);
73042 }
73043
73044+#ifdef CONFIG_PAX_REFCOUNT
73045+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
73046+{
73047+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
73048+
73049+ return (long)atomic_inc_return_unchecked(v);
73050+}
73051+#endif
73052+
73053 static inline long atomic_long_dec_return(atomic_long_t *l)
73054 {
73055 atomic_t *v = (atomic_t *)l;
73056@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
73057
73058 #endif /* BITS_PER_LONG == 64 */
73059
73060+#ifdef CONFIG_PAX_REFCOUNT
73061+static inline void pax_refcount_needs_these_functions(void)
73062+{
73063+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
73064+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
73065+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
73066+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
73067+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
73068+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
73069+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
73070+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
73071+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
73072+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
73073+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
73074+#ifdef CONFIG_X86
73075+ atomic_clear_mask_unchecked(0, NULL);
73076+ atomic_set_mask_unchecked(0, NULL);
73077+#endif
73078+
73079+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
73080+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
73081+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
73082+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
73083+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
73084+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
73085+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
73086+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
73087+}
73088+#else
73089+#define atomic_read_unchecked(v) atomic_read(v)
73090+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
73091+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
73092+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
73093+#define atomic_inc_unchecked(v) atomic_inc(v)
73094+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
73095+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
73096+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
73097+#define atomic_dec_unchecked(v) atomic_dec(v)
73098+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
73099+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
73100+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
73101+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
73102+
73103+#define atomic_long_read_unchecked(v) atomic_long_read(v)
73104+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
73105+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
73106+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
73107+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
73108+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
73109+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
73110+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
73111+#endif
73112+
73113 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
73114diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
73115index 33bd2de..f31bff97 100644
73116--- a/include/asm-generic/atomic.h
73117+++ b/include/asm-generic/atomic.h
73118@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
73119 * Atomically clears the bits set in @mask from @v
73120 */
73121 #ifndef atomic_clear_mask
73122-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
73123+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
73124 {
73125 unsigned long flags;
73126
73127diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
73128index b18ce4f..2ee2843 100644
73129--- a/include/asm-generic/atomic64.h
73130+++ b/include/asm-generic/atomic64.h
73131@@ -16,6 +16,8 @@ typedef struct {
73132 long long counter;
73133 } atomic64_t;
73134
73135+typedef atomic64_t atomic64_unchecked_t;
73136+
73137 #define ATOMIC64_INIT(i) { (i) }
73138
73139 extern long long atomic64_read(const atomic64_t *v);
73140@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
73141 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
73142 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
73143
73144+#define atomic64_read_unchecked(v) atomic64_read(v)
73145+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
73146+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
73147+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
73148+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
73149+#define atomic64_inc_unchecked(v) atomic64_inc(v)
73150+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
73151+#define atomic64_dec_unchecked(v) atomic64_dec(v)
73152+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
73153+
73154 #endif /* _ASM_GENERIC_ATOMIC64_H */
73155diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
73156index 1bfcfe5..e04c5c9 100644
73157--- a/include/asm-generic/cache.h
73158+++ b/include/asm-generic/cache.h
73159@@ -6,7 +6,7 @@
73160 * cache lines need to provide their own cache.h.
73161 */
73162
73163-#define L1_CACHE_SHIFT 5
73164-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
73165+#define L1_CACHE_SHIFT 5UL
73166+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
73167
73168 #endif /* __ASM_GENERIC_CACHE_H */
73169diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
73170index 0d68a1e..b74a761 100644
73171--- a/include/asm-generic/emergency-restart.h
73172+++ b/include/asm-generic/emergency-restart.h
73173@@ -1,7 +1,7 @@
73174 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
73175 #define _ASM_GENERIC_EMERGENCY_RESTART_H
73176
73177-static inline void machine_emergency_restart(void)
73178+static inline __noreturn void machine_emergency_restart(void)
73179 {
73180 machine_restart(NULL);
73181 }
73182diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
73183index 90f99c7..00ce236 100644
73184--- a/include/asm-generic/kmap_types.h
73185+++ b/include/asm-generic/kmap_types.h
73186@@ -2,9 +2,9 @@
73187 #define _ASM_GENERIC_KMAP_TYPES_H
73188
73189 #ifdef __WITH_KM_FENCE
73190-# define KM_TYPE_NR 41
73191+# define KM_TYPE_NR 42
73192 #else
73193-# define KM_TYPE_NR 20
73194+# define KM_TYPE_NR 21
73195 #endif
73196
73197 #endif
73198diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
73199index 9ceb03b..62b0b8f 100644
73200--- a/include/asm-generic/local.h
73201+++ b/include/asm-generic/local.h
73202@@ -23,24 +23,37 @@ typedef struct
73203 atomic_long_t a;
73204 } local_t;
73205
73206+typedef struct {
73207+ atomic_long_unchecked_t a;
73208+} local_unchecked_t;
73209+
73210 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
73211
73212 #define local_read(l) atomic_long_read(&(l)->a)
73213+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
73214 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
73215+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
73216 #define local_inc(l) atomic_long_inc(&(l)->a)
73217+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
73218 #define local_dec(l) atomic_long_dec(&(l)->a)
73219+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
73220 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
73221+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
73222 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
73223+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
73224
73225 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
73226 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
73227 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
73228 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
73229 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
73230+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
73231 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
73232 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
73233+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
73234
73235 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73236+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
73237 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
73238 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
73239 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
73240diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
73241index 725612b..9cc513a 100644
73242--- a/include/asm-generic/pgtable-nopmd.h
73243+++ b/include/asm-generic/pgtable-nopmd.h
73244@@ -1,14 +1,19 @@
73245 #ifndef _PGTABLE_NOPMD_H
73246 #define _PGTABLE_NOPMD_H
73247
73248-#ifndef __ASSEMBLY__
73249-
73250 #include <asm-generic/pgtable-nopud.h>
73251
73252-struct mm_struct;
73253-
73254 #define __PAGETABLE_PMD_FOLDED
73255
73256+#define PMD_SHIFT PUD_SHIFT
73257+#define PTRS_PER_PMD 1
73258+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
73259+#define PMD_MASK (~(PMD_SIZE-1))
73260+
73261+#ifndef __ASSEMBLY__
73262+
73263+struct mm_struct;
73264+
73265 /*
73266 * Having the pmd type consist of a pud gets the size right, and allows
73267 * us to conceptually access the pud entry that this pmd is folded into
73268@@ -16,11 +21,6 @@ struct mm_struct;
73269 */
73270 typedef struct { pud_t pud; } pmd_t;
73271
73272-#define PMD_SHIFT PUD_SHIFT
73273-#define PTRS_PER_PMD 1
73274-#define PMD_SIZE (1UL << PMD_SHIFT)
73275-#define PMD_MASK (~(PMD_SIZE-1))
73276-
73277 /*
73278 * The "pud_xxx()" functions here are trivial for a folded two-level
73279 * setup: the pmd is never bad, and a pmd always exists (as it's folded
73280diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
73281index 810431d..0ec4804f 100644
73282--- a/include/asm-generic/pgtable-nopud.h
73283+++ b/include/asm-generic/pgtable-nopud.h
73284@@ -1,10 +1,15 @@
73285 #ifndef _PGTABLE_NOPUD_H
73286 #define _PGTABLE_NOPUD_H
73287
73288-#ifndef __ASSEMBLY__
73289-
73290 #define __PAGETABLE_PUD_FOLDED
73291
73292+#define PUD_SHIFT PGDIR_SHIFT
73293+#define PTRS_PER_PUD 1
73294+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
73295+#define PUD_MASK (~(PUD_SIZE-1))
73296+
73297+#ifndef __ASSEMBLY__
73298+
73299 /*
73300 * Having the pud type consist of a pgd gets the size right, and allows
73301 * us to conceptually access the pgd entry that this pud is folded into
73302@@ -12,11 +17,6 @@
73303 */
73304 typedef struct { pgd_t pgd; } pud_t;
73305
73306-#define PUD_SHIFT PGDIR_SHIFT
73307-#define PTRS_PER_PUD 1
73308-#define PUD_SIZE (1UL << PUD_SHIFT)
73309-#define PUD_MASK (~(PUD_SIZE-1))
73310-
73311 /*
73312 * The "pgd_xxx()" functions here are trivial for a folded two-level
73313 * setup: the pud is never bad, and a pud always exists (as it's folded
73314@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
73315 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
73316
73317 #define pgd_populate(mm, pgd, pud) do { } while (0)
73318+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
73319 /*
73320 * (puds are folded into pgds so this doesn't get actually called,
73321 * but the define is needed for a generic inline function.)
73322diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
73323index a59ff51..2594a70 100644
73324--- a/include/asm-generic/pgtable.h
73325+++ b/include/asm-generic/pgtable.h
73326@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
73327 }
73328 #endif /* CONFIG_NUMA_BALANCING */
73329
73330+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
73331+static inline unsigned long pax_open_kernel(void) { return 0; }
73332+#endif
73333+
73334+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
73335+static inline unsigned long pax_close_kernel(void) { return 0; }
73336+#endif
73337+
73338 #endif /* CONFIG_MMU */
73339
73340 #endif /* !__ASSEMBLY__ */
73341diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
73342index c184aa8..d049942 100644
73343--- a/include/asm-generic/uaccess.h
73344+++ b/include/asm-generic/uaccess.h
73345@@ -343,4 +343,12 @@ clear_user(void __user *to, unsigned long n)
73346 return __clear_user(to, n);
73347 }
73348
73349+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
73350+//static inline unsigned long pax_open_userland(void) { return 0; }
73351+#endif
73352+
73353+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
73354+//static inline unsigned long pax_close_userland(void) { return 0; }
73355+#endif
73356+
73357 #endif /* __ASM_GENERIC_UACCESS_H */
73358diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
73359index eb58d2d..df131bf 100644
73360--- a/include/asm-generic/vmlinux.lds.h
73361+++ b/include/asm-generic/vmlinux.lds.h
73362@@ -239,6 +239,7 @@
73363 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
73364 VMLINUX_SYMBOL(__start_rodata) = .; \
73365 *(.rodata) *(.rodata.*) \
73366+ *(.data..read_only) \
73367 *(__vermagic) /* Kernel version magic */ \
73368 . = ALIGN(8); \
73369 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
73370@@ -749,17 +750,18 @@
73371 * section in the linker script will go there too. @phdr should have
73372 * a leading colon.
73373 *
73374- * Note that this macros defines __per_cpu_load as an absolute symbol.
73375+ * Note that this macros defines per_cpu_load as an absolute symbol.
73376 * If there is no need to put the percpu section at a predetermined
73377 * address, use PERCPU_SECTION.
73378 */
73379 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
73380- VMLINUX_SYMBOL(__per_cpu_load) = .; \
73381- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
73382+ per_cpu_load = .; \
73383+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
73384 - LOAD_OFFSET) { \
73385+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
73386 PERCPU_INPUT(cacheline) \
73387 } phdr \
73388- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
73389+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
73390
73391 /**
73392 * PERCPU_SECTION - define output section for percpu area, simple version
73393diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
73394index 418d270..bfd2794 100644
73395--- a/include/crypto/algapi.h
73396+++ b/include/crypto/algapi.h
73397@@ -34,7 +34,7 @@ struct crypto_type {
73398 unsigned int maskclear;
73399 unsigned int maskset;
73400 unsigned int tfmsize;
73401-};
73402+} __do_const;
73403
73404 struct crypto_instance {
73405 struct crypto_alg alg;
73406diff --git a/include/drm/drmP.h b/include/drm/drmP.h
73407index 63d17ee..716de2b 100644
73408--- a/include/drm/drmP.h
73409+++ b/include/drm/drmP.h
73410@@ -72,6 +72,7 @@
73411 #include <linux/workqueue.h>
73412 #include <linux/poll.h>
73413 #include <asm/pgalloc.h>
73414+#include <asm/local.h>
73415 #include <drm/drm.h>
73416 #include <drm/drm_sarea.h>
73417
73418@@ -296,10 +297,12 @@ do { \
73419 * \param cmd command.
73420 * \param arg argument.
73421 */
73422-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
73423+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
73424+ struct drm_file *file_priv);
73425+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
73426 struct drm_file *file_priv);
73427
73428-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73429+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
73430 unsigned long arg);
73431
73432 #define DRM_IOCTL_NR(n) _IOC_NR(n)
73433@@ -314,10 +317,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73434 struct drm_ioctl_desc {
73435 unsigned int cmd;
73436 int flags;
73437- drm_ioctl_t *func;
73438+ drm_ioctl_t func;
73439 unsigned int cmd_drv;
73440 const char *name;
73441-};
73442+} __do_const;
73443
73444 /**
73445 * Creates a driver or general drm_ioctl_desc array entry for the given
73446@@ -1015,7 +1018,7 @@ struct drm_info_list {
73447 int (*show)(struct seq_file*, void*); /** show callback */
73448 u32 driver_features; /**< Required driver features for this entry */
73449 void *data;
73450-};
73451+} __do_const;
73452
73453 /**
73454 * debugfs node structure. This structure represents a debugfs file.
73455@@ -1088,7 +1091,7 @@ struct drm_device {
73456
73457 /** \name Usage Counters */
73458 /*@{ */
73459- int open_count; /**< Outstanding files open */
73460+ local_t open_count; /**< Outstanding files open */
73461 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
73462 atomic_t vma_count; /**< Outstanding vma areas open */
73463 int buf_use; /**< Buffers in use -- cannot alloc */
73464@@ -1099,7 +1102,7 @@ struct drm_device {
73465 /*@{ */
73466 unsigned long counters;
73467 enum drm_stat_type types[15];
73468- atomic_t counts[15];
73469+ atomic_unchecked_t counts[15];
73470 /*@} */
73471
73472 struct list_head filelist;
73473diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
73474index f43d556..94d9343 100644
73475--- a/include/drm/drm_crtc_helper.h
73476+++ b/include/drm/drm_crtc_helper.h
73477@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
73478 struct drm_connector *connector);
73479 /* disable encoder when not in use - more explicit than dpms off */
73480 void (*disable)(struct drm_encoder *encoder);
73481-};
73482+} __no_const;
73483
73484 /**
73485 * drm_connector_helper_funcs - helper operations for connectors
73486diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
73487index 72dcbe8..8db58d7 100644
73488--- a/include/drm/ttm/ttm_memory.h
73489+++ b/include/drm/ttm/ttm_memory.h
73490@@ -48,7 +48,7 @@
73491
73492 struct ttm_mem_shrink {
73493 int (*do_shrink) (struct ttm_mem_shrink *);
73494-};
73495+} __no_const;
73496
73497 /**
73498 * struct ttm_mem_global - Global memory accounting structure.
73499diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
73500index 4b840e8..155d235 100644
73501--- a/include/keys/asymmetric-subtype.h
73502+++ b/include/keys/asymmetric-subtype.h
73503@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
73504 /* Verify the signature on a key of this subtype (optional) */
73505 int (*verify_signature)(const struct key *key,
73506 const struct public_key_signature *sig);
73507-};
73508+} __do_const;
73509
73510 /**
73511 * asymmetric_key_subtype - Get the subtype from an asymmetric key
73512diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
73513index c1da539..1dcec55 100644
73514--- a/include/linux/atmdev.h
73515+++ b/include/linux/atmdev.h
73516@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
73517 #endif
73518
73519 struct k_atm_aal_stats {
73520-#define __HANDLE_ITEM(i) atomic_t i
73521+#define __HANDLE_ITEM(i) atomic_unchecked_t i
73522 __AAL_STAT_ITEMS
73523 #undef __HANDLE_ITEM
73524 };
73525@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
73526 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
73527 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
73528 struct module *owner;
73529-};
73530+} __do_const ;
73531
73532 struct atmphy_ops {
73533 int (*start)(struct atm_dev *dev);
73534diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
73535index 70cf138..0418ee2 100644
73536--- a/include/linux/binfmts.h
73537+++ b/include/linux/binfmts.h
73538@@ -73,8 +73,10 @@ struct linux_binfmt {
73539 int (*load_binary)(struct linux_binprm *);
73540 int (*load_shlib)(struct file *);
73541 int (*core_dump)(struct coredump_params *cprm);
73542+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
73543+ void (*handle_mmap)(struct file *);
73544 unsigned long min_coredump; /* minimal dump size */
73545-};
73546+} __do_const;
73547
73548 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
73549
73550diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
73551index 2fdb4a4..54aad7e 100644
73552--- a/include/linux/blkdev.h
73553+++ b/include/linux/blkdev.h
73554@@ -1526,7 +1526,7 @@ struct block_device_operations {
73555 /* this callback is with swap_lock and sometimes page table lock held */
73556 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
73557 struct module *owner;
73558-};
73559+} __do_const;
73560
73561 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
73562 unsigned long);
73563diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
73564index 7c2e030..b72475d 100644
73565--- a/include/linux/blktrace_api.h
73566+++ b/include/linux/blktrace_api.h
73567@@ -23,7 +23,7 @@ struct blk_trace {
73568 struct dentry *dir;
73569 struct dentry *dropped_file;
73570 struct dentry *msg_file;
73571- atomic_t dropped;
73572+ atomic_unchecked_t dropped;
73573 };
73574
73575 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
73576diff --git a/include/linux/cache.h b/include/linux/cache.h
73577index 4c57065..4307975 100644
73578--- a/include/linux/cache.h
73579+++ b/include/linux/cache.h
73580@@ -16,6 +16,10 @@
73581 #define __read_mostly
73582 #endif
73583
73584+#ifndef __read_only
73585+#define __read_only __read_mostly
73586+#endif
73587+
73588 #ifndef ____cacheline_aligned
73589 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
73590 #endif
73591diff --git a/include/linux/capability.h b/include/linux/capability.h
73592index d9a4f7f4..19f77d6 100644
73593--- a/include/linux/capability.h
73594+++ b/include/linux/capability.h
73595@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
73596 extern bool nsown_capable(int cap);
73597 extern bool inode_capable(const struct inode *inode, int cap);
73598 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
73599+extern bool capable_nolog(int cap);
73600+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
73601+extern bool inode_capable_nolog(const struct inode *inode, int cap);
73602
73603 /* audit system wants to get cap info from files as well */
73604 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
73605
73606+extern int is_privileged_binary(const struct dentry *dentry);
73607+
73608 #endif /* !_LINUX_CAPABILITY_H */
73609diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
73610index 8609d57..86e4d79 100644
73611--- a/include/linux/cdrom.h
73612+++ b/include/linux/cdrom.h
73613@@ -87,7 +87,6 @@ struct cdrom_device_ops {
73614
73615 /* driver specifications */
73616 const int capability; /* capability flags */
73617- int n_minors; /* number of active minor devices */
73618 /* handle uniform packets for scsi type devices (scsi,atapi) */
73619 int (*generic_packet) (struct cdrom_device_info *,
73620 struct packet_command *);
73621diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
73622index 4ce9056..86caac6 100644
73623--- a/include/linux/cleancache.h
73624+++ b/include/linux/cleancache.h
73625@@ -31,7 +31,7 @@ struct cleancache_ops {
73626 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
73627 void (*invalidate_inode)(int, struct cleancache_filekey);
73628 void (*invalidate_fs)(int);
73629-};
73630+} __no_const;
73631
73632 extern struct cleancache_ops *
73633 cleancache_register_ops(struct cleancache_ops *ops);
73634diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
73635index 1186098..f87e53d 100644
73636--- a/include/linux/clk-provider.h
73637+++ b/include/linux/clk-provider.h
73638@@ -132,6 +132,7 @@ struct clk_ops {
73639 unsigned long);
73640 void (*init)(struct clk_hw *hw);
73641 };
73642+typedef struct clk_ops __no_const clk_ops_no_const;
73643
73644 /**
73645 * struct clk_init_data - holds init data that's common to all clocks and is
73646diff --git a/include/linux/compat.h b/include/linux/compat.h
73647index 7f0c1dd..206ac34 100644
73648--- a/include/linux/compat.h
73649+++ b/include/linux/compat.h
73650@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
73651 compat_size_t __user *len_ptr);
73652
73653 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
73654-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
73655+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
73656 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
73657 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
73658 compat_ssize_t msgsz, int msgflg);
73659@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
73660 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
73661 compat_ulong_t addr, compat_ulong_t data);
73662 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73663- compat_long_t addr, compat_long_t data);
73664+ compat_ulong_t addr, compat_ulong_t data);
73665
73666 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
73667 /*
73668@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
73669
73670 int compat_restore_altstack(const compat_stack_t __user *uss);
73671 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
73672+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
73673
73674 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
73675 struct compat_timespec __user *interval);
73676diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
73677index 842de22..7f3a41f 100644
73678--- a/include/linux/compiler-gcc4.h
73679+++ b/include/linux/compiler-gcc4.h
73680@@ -39,9 +39,29 @@
73681 # define __compiletime_warning(message) __attribute__((warning(message)))
73682 # define __compiletime_error(message) __attribute__((error(message)))
73683 #endif /* __CHECKER__ */
73684+
73685+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
73686+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
73687+#define __bos0(ptr) __bos((ptr), 0)
73688+#define __bos1(ptr) __bos((ptr), 1)
73689 #endif /* GCC_VERSION >= 40300 */
73690
73691 #if GCC_VERSION >= 40500
73692+
73693+#ifdef CONSTIFY_PLUGIN
73694+#define __no_const __attribute__((no_const))
73695+#define __do_const __attribute__((do_const))
73696+#endif
73697+
73698+#ifdef SIZE_OVERFLOW_PLUGIN
73699+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
73700+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
73701+#endif
73702+
73703+#ifdef LATENT_ENTROPY_PLUGIN
73704+#define __latent_entropy __attribute__((latent_entropy))
73705+#endif
73706+
73707 /*
73708 * Mark a position in code as unreachable. This can be used to
73709 * suppress control flow warnings after asm blocks that transfer
73710diff --git a/include/linux/compiler.h b/include/linux/compiler.h
73711index 92669cd..1771a15 100644
73712--- a/include/linux/compiler.h
73713+++ b/include/linux/compiler.h
73714@@ -5,11 +5,14 @@
73715
73716 #ifdef __CHECKER__
73717 # define __user __attribute__((noderef, address_space(1)))
73718+# define __force_user __force __user
73719 # define __kernel __attribute__((address_space(0)))
73720+# define __force_kernel __force __kernel
73721 # define __safe __attribute__((safe))
73722 # define __force __attribute__((force))
73723 # define __nocast __attribute__((nocast))
73724 # define __iomem __attribute__((noderef, address_space(2)))
73725+# define __force_iomem __force __iomem
73726 # define __must_hold(x) __attribute__((context(x,1,1)))
73727 # define __acquires(x) __attribute__((context(x,0,1)))
73728 # define __releases(x) __attribute__((context(x,1,0)))
73729@@ -17,20 +20,37 @@
73730 # define __release(x) __context__(x,-1)
73731 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
73732 # define __percpu __attribute__((noderef, address_space(3)))
73733+# define __force_percpu __force __percpu
73734 #ifdef CONFIG_SPARSE_RCU_POINTER
73735 # define __rcu __attribute__((noderef, address_space(4)))
73736+# define __force_rcu __force __rcu
73737 #else
73738 # define __rcu
73739+# define __force_rcu
73740 #endif
73741 extern void __chk_user_ptr(const volatile void __user *);
73742 extern void __chk_io_ptr(const volatile void __iomem *);
73743 #else
73744-# define __user
73745-# define __kernel
73746+# ifdef CHECKER_PLUGIN
73747+//# define __user
73748+//# define __force_user
73749+//# define __kernel
73750+//# define __force_kernel
73751+# else
73752+# ifdef STRUCTLEAK_PLUGIN
73753+# define __user __attribute__((user))
73754+# else
73755+# define __user
73756+# endif
73757+# define __force_user
73758+# define __kernel
73759+# define __force_kernel
73760+# endif
73761 # define __safe
73762 # define __force
73763 # define __nocast
73764 # define __iomem
73765+# define __force_iomem
73766 # define __chk_user_ptr(x) (void)0
73767 # define __chk_io_ptr(x) (void)0
73768 # define __builtin_warning(x, y...) (1)
73769@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
73770 # define __release(x) (void)0
73771 # define __cond_lock(x,c) (c)
73772 # define __percpu
73773+# define __force_percpu
73774 # define __rcu
73775+# define __force_rcu
73776 #endif
73777
73778 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
73779@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73780 # define __attribute_const__ /* unimplemented */
73781 #endif
73782
73783+#ifndef __no_const
73784+# define __no_const
73785+#endif
73786+
73787+#ifndef __do_const
73788+# define __do_const
73789+#endif
73790+
73791+#ifndef __size_overflow
73792+# define __size_overflow(...)
73793+#endif
73794+
73795+#ifndef __intentional_overflow
73796+# define __intentional_overflow(...)
73797+#endif
73798+
73799+#ifndef __latent_entropy
73800+# define __latent_entropy
73801+#endif
73802+
73803 /*
73804 * Tell gcc if a function is cold. The compiler will assume any path
73805 * directly leading to the call is unlikely.
73806@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73807 #define __cold
73808 #endif
73809
73810+#ifndef __alloc_size
73811+#define __alloc_size(...)
73812+#endif
73813+
73814+#ifndef __bos
73815+#define __bos(ptr, arg)
73816+#endif
73817+
73818+#ifndef __bos0
73819+#define __bos0(ptr)
73820+#endif
73821+
73822+#ifndef __bos1
73823+#define __bos1(ptr)
73824+#endif
73825+
73826 /* Simple shorthand for a section definition */
73827 #ifndef __section
73828 # define __section(S) __attribute__ ((__section__(#S)))
73829@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73830 * use is to mediate communication between process-level code and irq/NMI
73831 * handlers, all running on the same CPU.
73832 */
73833-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
73834+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
73835+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
73836
73837 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
73838 #ifdef CONFIG_KPROBES
73839diff --git a/include/linux/completion.h b/include/linux/completion.h
73840index 33f0280..35c6568 100644
73841--- a/include/linux/completion.h
73842+++ b/include/linux/completion.h
73843@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
73844 extern void wait_for_completion(struct completion *);
73845 extern void wait_for_completion_io(struct completion *);
73846 extern int wait_for_completion_interruptible(struct completion *x);
73847-extern int wait_for_completion_killable(struct completion *x);
73848+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
73849 extern unsigned long wait_for_completion_timeout(struct completion *x,
73850 unsigned long timeout);
73851 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
73852 unsigned long timeout);
73853 extern long wait_for_completion_interruptible_timeout(
73854- struct completion *x, unsigned long timeout);
73855+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73856 extern long wait_for_completion_killable_timeout(
73857- struct completion *x, unsigned long timeout);
73858+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73859 extern bool try_wait_for_completion(struct completion *x);
73860 extern bool completion_done(struct completion *x);
73861
73862diff --git a/include/linux/configfs.h b/include/linux/configfs.h
73863index 34025df..d94bbbc 100644
73864--- a/include/linux/configfs.h
73865+++ b/include/linux/configfs.h
73866@@ -125,7 +125,7 @@ struct configfs_attribute {
73867 const char *ca_name;
73868 struct module *ca_owner;
73869 umode_t ca_mode;
73870-};
73871+} __do_const;
73872
73873 /*
73874 * Users often need to create attribute structures for their configurable
73875diff --git a/include/linux/cpu.h b/include/linux/cpu.h
73876index 9f3c7e8..a18c7b6 100644
73877--- a/include/linux/cpu.h
73878+++ b/include/linux/cpu.h
73879@@ -115,7 +115,7 @@ enum {
73880 /* Need to know about CPUs going up/down? */
73881 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
73882 #define cpu_notifier(fn, pri) { \
73883- static struct notifier_block fn##_nb __cpuinitdata = \
73884+ static struct notifier_block fn##_nb = \
73885 { .notifier_call = fn, .priority = pri }; \
73886 register_cpu_notifier(&fn##_nb); \
73887 }
73888diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
73889index 037d36a..ca5fe6e 100644
73890--- a/include/linux/cpufreq.h
73891+++ b/include/linux/cpufreq.h
73892@@ -262,7 +262,7 @@ struct cpufreq_driver {
73893 int (*suspend) (struct cpufreq_policy *policy);
73894 int (*resume) (struct cpufreq_policy *policy);
73895 struct freq_attr **attr;
73896-};
73897+} __do_const;
73898
73899 /* flags */
73900
73901@@ -321,6 +321,7 @@ struct global_attr {
73902 ssize_t (*store)(struct kobject *a, struct attribute *b,
73903 const char *c, size_t count);
73904 };
73905+typedef struct global_attr __no_const global_attr_no_const;
73906
73907 #define define_one_global_ro(_name) \
73908 static struct global_attr _name = \
73909diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
73910index 8f04062..900239a 100644
73911--- a/include/linux/cpuidle.h
73912+++ b/include/linux/cpuidle.h
73913@@ -52,7 +52,8 @@ struct cpuidle_state {
73914 int index);
73915
73916 int (*enter_dead) (struct cpuidle_device *dev, int index);
73917-};
73918+} __do_const;
73919+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
73920
73921 /* Idle State Flags */
73922 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
73923@@ -191,7 +192,7 @@ struct cpuidle_governor {
73924 void (*reflect) (struct cpuidle_device *dev, int index);
73925
73926 struct module *owner;
73927-};
73928+} __do_const;
73929
73930 #ifdef CONFIG_CPU_IDLE
73931
73932diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
73933index d08e4d2..95fad61 100644
73934--- a/include/linux/cpumask.h
73935+++ b/include/linux/cpumask.h
73936@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73937 }
73938
73939 /* Valid inputs for n are -1 and 0. */
73940-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73941+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73942 {
73943 return n+1;
73944 }
73945
73946-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73947+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
73948 {
73949 return n+1;
73950 }
73951
73952-static inline unsigned int cpumask_next_and(int n,
73953+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
73954 const struct cpumask *srcp,
73955 const struct cpumask *andp)
73956 {
73957@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73958 *
73959 * Returns >= nr_cpu_ids if no further cpus set.
73960 */
73961-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73962+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73963 {
73964 /* -1 is a legal arg here. */
73965 if (n != -1)
73966@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73967 *
73968 * Returns >= nr_cpu_ids if no further cpus unset.
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 /* -1 is a legal arg here. */
73974 if (n != -1)
73975@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73976 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
73977 }
73978
73979-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
73980+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
73981 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
73982
73983 /**
73984diff --git a/include/linux/cred.h b/include/linux/cred.h
73985index 04421e8..6bce4ef 100644
73986--- a/include/linux/cred.h
73987+++ b/include/linux/cred.h
73988@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
73989 static inline void validate_process_creds(void)
73990 {
73991 }
73992+static inline void validate_task_creds(struct task_struct *task)
73993+{
73994+}
73995 #endif
73996
73997 /**
73998diff --git a/include/linux/crypto.h b/include/linux/crypto.h
73999index b92eadf..b4ecdc1 100644
74000--- a/include/linux/crypto.h
74001+++ b/include/linux/crypto.h
74002@@ -373,7 +373,7 @@ struct cipher_tfm {
74003 const u8 *key, unsigned int keylen);
74004 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74005 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
74006-};
74007+} __no_const;
74008
74009 struct hash_tfm {
74010 int (*init)(struct hash_desc *desc);
74011@@ -394,13 +394,13 @@ struct compress_tfm {
74012 int (*cot_decompress)(struct crypto_tfm *tfm,
74013 const u8 *src, unsigned int slen,
74014 u8 *dst, unsigned int *dlen);
74015-};
74016+} __no_const;
74017
74018 struct rng_tfm {
74019 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
74020 unsigned int dlen);
74021 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
74022-};
74023+} __no_const;
74024
74025 #define crt_ablkcipher crt_u.ablkcipher
74026 #define crt_aead crt_u.aead
74027diff --git a/include/linux/ctype.h b/include/linux/ctype.h
74028index 653589e..4ef254a 100644
74029--- a/include/linux/ctype.h
74030+++ b/include/linux/ctype.h
74031@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
74032 * Fast implementation of tolower() for internal usage. Do not use in your
74033 * code.
74034 */
74035-static inline char _tolower(const char c)
74036+static inline unsigned char _tolower(const unsigned char c)
74037 {
74038 return c | 0x20;
74039 }
74040diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
74041index 7925bf0..d5143d2 100644
74042--- a/include/linux/decompress/mm.h
74043+++ b/include/linux/decompress/mm.h
74044@@ -77,7 +77,7 @@ static void free(void *where)
74045 * warnings when not needed (indeed large_malloc / large_free are not
74046 * needed by inflate */
74047
74048-#define malloc(a) kmalloc(a, GFP_KERNEL)
74049+#define malloc(a) kmalloc((a), GFP_KERNEL)
74050 #define free(a) kfree(a)
74051
74052 #define large_malloc(a) vmalloc(a)
74053diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
74054index fe8c447..bdc1f33 100644
74055--- a/include/linux/devfreq.h
74056+++ b/include/linux/devfreq.h
74057@@ -114,7 +114,7 @@ struct devfreq_governor {
74058 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
74059 int (*event_handler)(struct devfreq *devfreq,
74060 unsigned int event, void *data);
74061-};
74062+} __do_const;
74063
74064 /**
74065 * struct devfreq - Device devfreq structure
74066diff --git a/include/linux/device.h b/include/linux/device.h
74067index c0a1261..dba7569 100644
74068--- a/include/linux/device.h
74069+++ b/include/linux/device.h
74070@@ -290,7 +290,7 @@ struct subsys_interface {
74071 struct list_head node;
74072 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
74073 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
74074-};
74075+} __do_const;
74076
74077 int subsys_interface_register(struct subsys_interface *sif);
74078 void subsys_interface_unregister(struct subsys_interface *sif);
74079@@ -473,7 +473,7 @@ struct device_type {
74080 void (*release)(struct device *dev);
74081
74082 const struct dev_pm_ops *pm;
74083-};
74084+} __do_const;
74085
74086 /* interface for exporting device attributes */
74087 struct device_attribute {
74088@@ -483,11 +483,12 @@ struct device_attribute {
74089 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
74090 const char *buf, size_t count);
74091 };
74092+typedef struct device_attribute __no_const device_attribute_no_const;
74093
74094 struct dev_ext_attribute {
74095 struct device_attribute attr;
74096 void *var;
74097-};
74098+} __do_const;
74099
74100 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
74101 char *buf);
74102diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
74103index 94af418..b1ca7a2 100644
74104--- a/include/linux/dma-mapping.h
74105+++ b/include/linux/dma-mapping.h
74106@@ -54,7 +54,7 @@ struct dma_map_ops {
74107 u64 (*get_required_mask)(struct device *dev);
74108 #endif
74109 int is_phys;
74110-};
74111+} __do_const;
74112
74113 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
74114
74115diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
74116index 96d3e4a..dc36433 100644
74117--- a/include/linux/dmaengine.h
74118+++ b/include/linux/dmaengine.h
74119@@ -1035,9 +1035,9 @@ struct dma_pinned_list {
74120 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
74121 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
74122
74123-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74124+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
74125 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
74126-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74127+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
74128 struct dma_pinned_list *pinned_list, struct page *page,
74129 unsigned int offset, size_t len);
74130
74131diff --git a/include/linux/efi.h b/include/linux/efi.h
74132index 2bc0ad7..3f7b006 100644
74133--- a/include/linux/efi.h
74134+++ b/include/linux/efi.h
74135@@ -745,6 +745,7 @@ struct efivar_operations {
74136 efi_set_variable_t *set_variable;
74137 efi_query_variable_store_t *query_variable_store;
74138 };
74139+typedef struct efivar_operations __no_const efivar_operations_no_const;
74140
74141 struct efivars {
74142 /*
74143diff --git a/include/linux/elf.h b/include/linux/elf.h
74144index 40a3c0e..4c45a38 100644
74145--- a/include/linux/elf.h
74146+++ b/include/linux/elf.h
74147@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
74148 #define elf_note elf32_note
74149 #define elf_addr_t Elf32_Off
74150 #define Elf_Half Elf32_Half
74151+#define elf_dyn Elf32_Dyn
74152
74153 #else
74154
74155@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
74156 #define elf_note elf64_note
74157 #define elf_addr_t Elf64_Off
74158 #define Elf_Half Elf64_Half
74159+#define elf_dyn Elf64_Dyn
74160
74161 #endif
74162
74163diff --git a/include/linux/err.h b/include/linux/err.h
74164index f2edce2..cc2082c 100644
74165--- a/include/linux/err.h
74166+++ b/include/linux/err.h
74167@@ -19,12 +19,12 @@
74168
74169 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
74170
74171-static inline void * __must_check ERR_PTR(long error)
74172+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
74173 {
74174 return (void *) error;
74175 }
74176
74177-static inline long __must_check PTR_ERR(const void *ptr)
74178+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
74179 {
74180 return (long) ptr;
74181 }
74182diff --git a/include/linux/extcon.h b/include/linux/extcon.h
74183index fcb51c8..bdafcf6 100644
74184--- a/include/linux/extcon.h
74185+++ b/include/linux/extcon.h
74186@@ -134,7 +134,7 @@ struct extcon_dev {
74187 /* /sys/class/extcon/.../mutually_exclusive/... */
74188 struct attribute_group attr_g_muex;
74189 struct attribute **attrs_muex;
74190- struct device_attribute *d_attrs_muex;
74191+ device_attribute_no_const *d_attrs_muex;
74192 };
74193
74194 /**
74195diff --git a/include/linux/fb.h b/include/linux/fb.h
74196index d49c60f..2834fbe 100644
74197--- a/include/linux/fb.h
74198+++ b/include/linux/fb.h
74199@@ -304,7 +304,7 @@ struct fb_ops {
74200 /* called at KDB enter and leave time to prepare the console */
74201 int (*fb_debug_enter)(struct fb_info *info);
74202 int (*fb_debug_leave)(struct fb_info *info);
74203-};
74204+} __do_const;
74205
74206 #ifdef CONFIG_FB_TILEBLITTING
74207 #define FB_TILE_CURSOR_NONE 0
74208diff --git a/include/linux/filter.h b/include/linux/filter.h
74209index f65f5a6..2f4f93a 100644
74210--- a/include/linux/filter.h
74211+++ b/include/linux/filter.h
74212@@ -20,6 +20,7 @@ struct compat_sock_fprog {
74213
74214 struct sk_buff;
74215 struct sock;
74216+struct bpf_jit_work;
74217
74218 struct sk_filter
74219 {
74220@@ -27,6 +28,9 @@ struct sk_filter
74221 unsigned int len; /* Number of filter blocks */
74222 unsigned int (*bpf_func)(const struct sk_buff *skb,
74223 const struct sock_filter *filter);
74224+#ifdef CONFIG_BPF_JIT
74225+ struct bpf_jit_work *work;
74226+#endif
74227 struct rcu_head rcu;
74228 struct sock_filter insns[0];
74229 };
74230diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
74231index 8293262..2b3b8bd 100644
74232--- a/include/linux/frontswap.h
74233+++ b/include/linux/frontswap.h
74234@@ -11,7 +11,7 @@ struct frontswap_ops {
74235 int (*load)(unsigned, pgoff_t, struct page *);
74236 void (*invalidate_page)(unsigned, pgoff_t);
74237 void (*invalidate_area)(unsigned);
74238-};
74239+} __no_const;
74240
74241 extern bool frontswap_enabled;
74242 extern struct frontswap_ops *
74243diff --git a/include/linux/fs.h b/include/linux/fs.h
74244index 65c2be2..4c53f6e 100644
74245--- a/include/linux/fs.h
74246+++ b/include/linux/fs.h
74247@@ -1543,7 +1543,8 @@ struct file_operations {
74248 long (*fallocate)(struct file *file, int mode, loff_t offset,
74249 loff_t len);
74250 int (*show_fdinfo)(struct seq_file *m, struct file *f);
74251-};
74252+} __do_const;
74253+typedef struct file_operations __no_const file_operations_no_const;
74254
74255 struct inode_operations {
74256 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
74257@@ -2688,4 +2689,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
74258 inode->i_flags |= S_NOSEC;
74259 }
74260
74261+static inline bool is_sidechannel_device(const struct inode *inode)
74262+{
74263+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
74264+ umode_t mode = inode->i_mode;
74265+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
74266+#else
74267+ return false;
74268+#endif
74269+}
74270+
74271 #endif /* _LINUX_FS_H */
74272diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
74273index 2b93a9a..855d94a 100644
74274--- a/include/linux/fs_struct.h
74275+++ b/include/linux/fs_struct.h
74276@@ -6,7 +6,7 @@
74277 #include <linux/seqlock.h>
74278
74279 struct fs_struct {
74280- int users;
74281+ atomic_t users;
74282 spinlock_t lock;
74283 seqcount_t seq;
74284 int umask;
74285diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
74286index 5dfa0aa..6acf322 100644
74287--- a/include/linux/fscache-cache.h
74288+++ b/include/linux/fscache-cache.h
74289@@ -112,7 +112,7 @@ struct fscache_operation {
74290 fscache_operation_release_t release;
74291 };
74292
74293-extern atomic_t fscache_op_debug_id;
74294+extern atomic_unchecked_t fscache_op_debug_id;
74295 extern void fscache_op_work_func(struct work_struct *work);
74296
74297 extern void fscache_enqueue_operation(struct fscache_operation *);
74298@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
74299 INIT_WORK(&op->work, fscache_op_work_func);
74300 atomic_set(&op->usage, 1);
74301 op->state = FSCACHE_OP_ST_INITIALISED;
74302- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
74303+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
74304 op->processor = processor;
74305 op->release = release;
74306 INIT_LIST_HEAD(&op->pend_link);
74307diff --git a/include/linux/fscache.h b/include/linux/fscache.h
74308index 7a08623..4c07b0f 100644
74309--- a/include/linux/fscache.h
74310+++ b/include/linux/fscache.h
74311@@ -152,7 +152,7 @@ struct fscache_cookie_def {
74312 * - this is mandatory for any object that may have data
74313 */
74314 void (*now_uncached)(void *cookie_netfs_data);
74315-};
74316+} __do_const;
74317
74318 /*
74319 * fscache cached network filesystem type
74320diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
74321index a78680a..87bd73e 100644
74322--- a/include/linux/fsnotify.h
74323+++ b/include/linux/fsnotify.h
74324@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
74325 struct inode *inode = path->dentry->d_inode;
74326 __u32 mask = FS_ACCESS;
74327
74328+ if (is_sidechannel_device(inode))
74329+ return;
74330+
74331 if (S_ISDIR(inode->i_mode))
74332 mask |= FS_ISDIR;
74333
74334@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
74335 struct inode *inode = path->dentry->d_inode;
74336 __u32 mask = FS_MODIFY;
74337
74338+ if (is_sidechannel_device(inode))
74339+ return;
74340+
74341 if (S_ISDIR(inode->i_mode))
74342 mask |= FS_ISDIR;
74343
74344@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
74345 */
74346 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
74347 {
74348- return kstrdup(name, GFP_KERNEL);
74349+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
74350 }
74351
74352 /*
74353diff --git a/include/linux/genhd.h b/include/linux/genhd.h
74354index 9f3c275..911b591 100644
74355--- a/include/linux/genhd.h
74356+++ b/include/linux/genhd.h
74357@@ -194,7 +194,7 @@ struct gendisk {
74358 struct kobject *slave_dir;
74359
74360 struct timer_rand_state *random;
74361- atomic_t sync_io; /* RAID */
74362+ atomic_unchecked_t sync_io; /* RAID */
74363 struct disk_events *ev;
74364 #ifdef CONFIG_BLK_DEV_INTEGRITY
74365 struct blk_integrity *integrity;
74366diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
74367index 023bc34..b02b46a 100644
74368--- a/include/linux/genl_magic_func.h
74369+++ b/include/linux/genl_magic_func.h
74370@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
74371 },
74372
74373 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
74374-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
74375+static struct genl_ops ZZZ_genl_ops[] = {
74376 #include GENL_MAGIC_INCLUDE_FILE
74377 };
74378
74379diff --git a/include/linux/gfp.h b/include/linux/gfp.h
74380index 0f615eb..5c3832f 100644
74381--- a/include/linux/gfp.h
74382+++ b/include/linux/gfp.h
74383@@ -35,6 +35,13 @@ struct vm_area_struct;
74384 #define ___GFP_NO_KSWAPD 0x400000u
74385 #define ___GFP_OTHER_NODE 0x800000u
74386 #define ___GFP_WRITE 0x1000000u
74387+
74388+#ifdef CONFIG_PAX_USERCOPY_SLABS
74389+#define ___GFP_USERCOPY 0x2000000u
74390+#else
74391+#define ___GFP_USERCOPY 0
74392+#endif
74393+
74394 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
74395
74396 /*
74397@@ -92,6 +99,7 @@ struct vm_area_struct;
74398 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
74399 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
74400 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
74401+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
74402
74403 /*
74404 * This may seem redundant, but it's a way of annotating false positives vs.
74405@@ -99,7 +107,7 @@ struct vm_area_struct;
74406 */
74407 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
74408
74409-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
74410+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
74411 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
74412
74413 /* This equals 0, but use constants in case they ever change */
74414@@ -153,6 +161,8 @@ struct vm_area_struct;
74415 /* 4GB DMA on some platforms */
74416 #define GFP_DMA32 __GFP_DMA32
74417
74418+#define GFP_USERCOPY __GFP_USERCOPY
74419+
74420 /* Convert GFP flags to their corresponding migrate type */
74421 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
74422 {
74423diff --git a/include/linux/gracl.h b/include/linux/gracl.h
74424new file mode 100644
74425index 0000000..ebe6d72
74426--- /dev/null
74427+++ b/include/linux/gracl.h
74428@@ -0,0 +1,319 @@
74429+#ifndef GR_ACL_H
74430+#define GR_ACL_H
74431+
74432+#include <linux/grdefs.h>
74433+#include <linux/resource.h>
74434+#include <linux/capability.h>
74435+#include <linux/dcache.h>
74436+#include <asm/resource.h>
74437+
74438+/* Major status information */
74439+
74440+#define GR_VERSION "grsecurity 2.9.1"
74441+#define GRSECURITY_VERSION 0x2901
74442+
74443+enum {
74444+ GR_SHUTDOWN = 0,
74445+ GR_ENABLE = 1,
74446+ GR_SPROLE = 2,
74447+ GR_RELOAD = 3,
74448+ GR_SEGVMOD = 4,
74449+ GR_STATUS = 5,
74450+ GR_UNSPROLE = 6,
74451+ GR_PASSSET = 7,
74452+ GR_SPROLEPAM = 8,
74453+};
74454+
74455+/* Password setup definitions
74456+ * kernel/grhash.c */
74457+enum {
74458+ GR_PW_LEN = 128,
74459+ GR_SALT_LEN = 16,
74460+ GR_SHA_LEN = 32,
74461+};
74462+
74463+enum {
74464+ GR_SPROLE_LEN = 64,
74465+};
74466+
74467+enum {
74468+ GR_NO_GLOB = 0,
74469+ GR_REG_GLOB,
74470+ GR_CREATE_GLOB
74471+};
74472+
74473+#define GR_NLIMITS 32
74474+
74475+/* Begin Data Structures */
74476+
74477+struct sprole_pw {
74478+ unsigned char *rolename;
74479+ unsigned char salt[GR_SALT_LEN];
74480+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
74481+};
74482+
74483+struct name_entry {
74484+ __u32 key;
74485+ ino_t inode;
74486+ dev_t device;
74487+ char *name;
74488+ __u16 len;
74489+ __u8 deleted;
74490+ struct name_entry *prev;
74491+ struct name_entry *next;
74492+};
74493+
74494+struct inodev_entry {
74495+ struct name_entry *nentry;
74496+ struct inodev_entry *prev;
74497+ struct inodev_entry *next;
74498+};
74499+
74500+struct acl_role_db {
74501+ struct acl_role_label **r_hash;
74502+ __u32 r_size;
74503+};
74504+
74505+struct inodev_db {
74506+ struct inodev_entry **i_hash;
74507+ __u32 i_size;
74508+};
74509+
74510+struct name_db {
74511+ struct name_entry **n_hash;
74512+ __u32 n_size;
74513+};
74514+
74515+struct crash_uid {
74516+ uid_t uid;
74517+ unsigned long expires;
74518+};
74519+
74520+struct gr_hash_struct {
74521+ void **table;
74522+ void **nametable;
74523+ void *first;
74524+ __u32 table_size;
74525+ __u32 used_size;
74526+ int type;
74527+};
74528+
74529+/* Userspace Grsecurity ACL data structures */
74530+
74531+struct acl_subject_label {
74532+ char *filename;
74533+ ino_t inode;
74534+ dev_t device;
74535+ __u32 mode;
74536+ kernel_cap_t cap_mask;
74537+ kernel_cap_t cap_lower;
74538+ kernel_cap_t cap_invert_audit;
74539+
74540+ struct rlimit res[GR_NLIMITS];
74541+ __u32 resmask;
74542+
74543+ __u8 user_trans_type;
74544+ __u8 group_trans_type;
74545+ uid_t *user_transitions;
74546+ gid_t *group_transitions;
74547+ __u16 user_trans_num;
74548+ __u16 group_trans_num;
74549+
74550+ __u32 sock_families[2];
74551+ __u32 ip_proto[8];
74552+ __u32 ip_type;
74553+ struct acl_ip_label **ips;
74554+ __u32 ip_num;
74555+ __u32 inaddr_any_override;
74556+
74557+ __u32 crashes;
74558+ unsigned long expires;
74559+
74560+ struct acl_subject_label *parent_subject;
74561+ struct gr_hash_struct *hash;
74562+ struct acl_subject_label *prev;
74563+ struct acl_subject_label *next;
74564+
74565+ struct acl_object_label **obj_hash;
74566+ __u32 obj_hash_size;
74567+ __u16 pax_flags;
74568+};
74569+
74570+struct role_allowed_ip {
74571+ __u32 addr;
74572+ __u32 netmask;
74573+
74574+ struct role_allowed_ip *prev;
74575+ struct role_allowed_ip *next;
74576+};
74577+
74578+struct role_transition {
74579+ char *rolename;
74580+
74581+ struct role_transition *prev;
74582+ struct role_transition *next;
74583+};
74584+
74585+struct acl_role_label {
74586+ char *rolename;
74587+ uid_t uidgid;
74588+ __u16 roletype;
74589+
74590+ __u16 auth_attempts;
74591+ unsigned long expires;
74592+
74593+ struct acl_subject_label *root_label;
74594+ struct gr_hash_struct *hash;
74595+
74596+ struct acl_role_label *prev;
74597+ struct acl_role_label *next;
74598+
74599+ struct role_transition *transitions;
74600+ struct role_allowed_ip *allowed_ips;
74601+ uid_t *domain_children;
74602+ __u16 domain_child_num;
74603+
74604+ umode_t umask;
74605+
74606+ struct acl_subject_label **subj_hash;
74607+ __u32 subj_hash_size;
74608+};
74609+
74610+struct user_acl_role_db {
74611+ struct acl_role_label **r_table;
74612+ __u32 num_pointers; /* Number of allocations to track */
74613+ __u32 num_roles; /* Number of roles */
74614+ __u32 num_domain_children; /* Number of domain children */
74615+ __u32 num_subjects; /* Number of subjects */
74616+ __u32 num_objects; /* Number of objects */
74617+};
74618+
74619+struct acl_object_label {
74620+ char *filename;
74621+ ino_t inode;
74622+ dev_t device;
74623+ __u32 mode;
74624+
74625+ struct acl_subject_label *nested;
74626+ struct acl_object_label *globbed;
74627+
74628+ /* next two structures not used */
74629+
74630+ struct acl_object_label *prev;
74631+ struct acl_object_label *next;
74632+};
74633+
74634+struct acl_ip_label {
74635+ char *iface;
74636+ __u32 addr;
74637+ __u32 netmask;
74638+ __u16 low, high;
74639+ __u8 mode;
74640+ __u32 type;
74641+ __u32 proto[8];
74642+
74643+ /* next two structures not used */
74644+
74645+ struct acl_ip_label *prev;
74646+ struct acl_ip_label *next;
74647+};
74648+
74649+struct gr_arg {
74650+ struct user_acl_role_db role_db;
74651+ unsigned char pw[GR_PW_LEN];
74652+ unsigned char salt[GR_SALT_LEN];
74653+ unsigned char sum[GR_SHA_LEN];
74654+ unsigned char sp_role[GR_SPROLE_LEN];
74655+ struct sprole_pw *sprole_pws;
74656+ dev_t segv_device;
74657+ ino_t segv_inode;
74658+ uid_t segv_uid;
74659+ __u16 num_sprole_pws;
74660+ __u16 mode;
74661+};
74662+
74663+struct gr_arg_wrapper {
74664+ struct gr_arg *arg;
74665+ __u32 version;
74666+ __u32 size;
74667+};
74668+
74669+struct subject_map {
74670+ struct acl_subject_label *user;
74671+ struct acl_subject_label *kernel;
74672+ struct subject_map *prev;
74673+ struct subject_map *next;
74674+};
74675+
74676+struct acl_subj_map_db {
74677+ struct subject_map **s_hash;
74678+ __u32 s_size;
74679+};
74680+
74681+/* End Data Structures Section */
74682+
74683+/* Hash functions generated by empirical testing by Brad Spengler
74684+ Makes good use of the low bits of the inode. Generally 0-1 times
74685+ in loop for successful match. 0-3 for unsuccessful match.
74686+ Shift/add algorithm with modulus of table size and an XOR*/
74687+
74688+static __inline__ unsigned int
74689+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
74690+{
74691+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
74692+}
74693+
74694+ static __inline__ unsigned int
74695+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
74696+{
74697+ return ((const unsigned long)userp % sz);
74698+}
74699+
74700+static __inline__ unsigned int
74701+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
74702+{
74703+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
74704+}
74705+
74706+static __inline__ unsigned int
74707+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
74708+{
74709+ return full_name_hash((const unsigned char *)name, len) % sz;
74710+}
74711+
74712+#define FOR_EACH_ROLE_START(role) \
74713+ role = role_list; \
74714+ while (role) {
74715+
74716+#define FOR_EACH_ROLE_END(role) \
74717+ role = role->prev; \
74718+ }
74719+
74720+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
74721+ subj = NULL; \
74722+ iter = 0; \
74723+ while (iter < role->subj_hash_size) { \
74724+ if (subj == NULL) \
74725+ subj = role->subj_hash[iter]; \
74726+ if (subj == NULL) { \
74727+ iter++; \
74728+ continue; \
74729+ }
74730+
74731+#define FOR_EACH_SUBJECT_END(subj,iter) \
74732+ subj = subj->next; \
74733+ if (subj == NULL) \
74734+ iter++; \
74735+ }
74736+
74737+
74738+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
74739+ subj = role->hash->first; \
74740+ while (subj != NULL) {
74741+
74742+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
74743+ subj = subj->next; \
74744+ }
74745+
74746+#endif
74747+
74748diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
74749new file mode 100644
74750index 0000000..33ebd1f
74751--- /dev/null
74752+++ b/include/linux/gracl_compat.h
74753@@ -0,0 +1,156 @@
74754+#ifndef GR_ACL_COMPAT_H
74755+#define GR_ACL_COMPAT_H
74756+
74757+#include <linux/resource.h>
74758+#include <asm/resource.h>
74759+
74760+struct sprole_pw_compat {
74761+ compat_uptr_t rolename;
74762+ unsigned char salt[GR_SALT_LEN];
74763+ unsigned char sum[GR_SHA_LEN];
74764+};
74765+
74766+struct gr_hash_struct_compat {
74767+ compat_uptr_t table;
74768+ compat_uptr_t nametable;
74769+ compat_uptr_t first;
74770+ __u32 table_size;
74771+ __u32 used_size;
74772+ int type;
74773+};
74774+
74775+struct acl_subject_label_compat {
74776+ compat_uptr_t filename;
74777+ compat_ino_t inode;
74778+ __u32 device;
74779+ __u32 mode;
74780+ kernel_cap_t cap_mask;
74781+ kernel_cap_t cap_lower;
74782+ kernel_cap_t cap_invert_audit;
74783+
74784+ struct compat_rlimit res[GR_NLIMITS];
74785+ __u32 resmask;
74786+
74787+ __u8 user_trans_type;
74788+ __u8 group_trans_type;
74789+ compat_uptr_t user_transitions;
74790+ compat_uptr_t group_transitions;
74791+ __u16 user_trans_num;
74792+ __u16 group_trans_num;
74793+
74794+ __u32 sock_families[2];
74795+ __u32 ip_proto[8];
74796+ __u32 ip_type;
74797+ compat_uptr_t ips;
74798+ __u32 ip_num;
74799+ __u32 inaddr_any_override;
74800+
74801+ __u32 crashes;
74802+ compat_ulong_t expires;
74803+
74804+ compat_uptr_t parent_subject;
74805+ compat_uptr_t hash;
74806+ compat_uptr_t prev;
74807+ compat_uptr_t next;
74808+
74809+ compat_uptr_t obj_hash;
74810+ __u32 obj_hash_size;
74811+ __u16 pax_flags;
74812+};
74813+
74814+struct role_allowed_ip_compat {
74815+ __u32 addr;
74816+ __u32 netmask;
74817+
74818+ compat_uptr_t prev;
74819+ compat_uptr_t next;
74820+};
74821+
74822+struct role_transition_compat {
74823+ compat_uptr_t rolename;
74824+
74825+ compat_uptr_t prev;
74826+ compat_uptr_t next;
74827+};
74828+
74829+struct acl_role_label_compat {
74830+ compat_uptr_t rolename;
74831+ uid_t uidgid;
74832+ __u16 roletype;
74833+
74834+ __u16 auth_attempts;
74835+ compat_ulong_t expires;
74836+
74837+ compat_uptr_t root_label;
74838+ compat_uptr_t hash;
74839+
74840+ compat_uptr_t prev;
74841+ compat_uptr_t next;
74842+
74843+ compat_uptr_t transitions;
74844+ compat_uptr_t allowed_ips;
74845+ compat_uptr_t domain_children;
74846+ __u16 domain_child_num;
74847+
74848+ umode_t umask;
74849+
74850+ compat_uptr_t subj_hash;
74851+ __u32 subj_hash_size;
74852+};
74853+
74854+struct user_acl_role_db_compat {
74855+ compat_uptr_t r_table;
74856+ __u32 num_pointers;
74857+ __u32 num_roles;
74858+ __u32 num_domain_children;
74859+ __u32 num_subjects;
74860+ __u32 num_objects;
74861+};
74862+
74863+struct acl_object_label_compat {
74864+ compat_uptr_t filename;
74865+ compat_ino_t inode;
74866+ __u32 device;
74867+ __u32 mode;
74868+
74869+ compat_uptr_t nested;
74870+ compat_uptr_t globbed;
74871+
74872+ compat_uptr_t prev;
74873+ compat_uptr_t next;
74874+};
74875+
74876+struct acl_ip_label_compat {
74877+ compat_uptr_t iface;
74878+ __u32 addr;
74879+ __u32 netmask;
74880+ __u16 low, high;
74881+ __u8 mode;
74882+ __u32 type;
74883+ __u32 proto[8];
74884+
74885+ compat_uptr_t prev;
74886+ compat_uptr_t next;
74887+};
74888+
74889+struct gr_arg_compat {
74890+ struct user_acl_role_db_compat role_db;
74891+ unsigned char pw[GR_PW_LEN];
74892+ unsigned char salt[GR_SALT_LEN];
74893+ unsigned char sum[GR_SHA_LEN];
74894+ unsigned char sp_role[GR_SPROLE_LEN];
74895+ compat_uptr_t sprole_pws;
74896+ __u32 segv_device;
74897+ compat_ino_t segv_inode;
74898+ uid_t segv_uid;
74899+ __u16 num_sprole_pws;
74900+ __u16 mode;
74901+};
74902+
74903+struct gr_arg_wrapper_compat {
74904+ compat_uptr_t arg;
74905+ __u32 version;
74906+ __u32 size;
74907+};
74908+
74909+#endif
74910diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
74911new file mode 100644
74912index 0000000..323ecf2
74913--- /dev/null
74914+++ b/include/linux/gralloc.h
74915@@ -0,0 +1,9 @@
74916+#ifndef __GRALLOC_H
74917+#define __GRALLOC_H
74918+
74919+void acl_free_all(void);
74920+int acl_alloc_stack_init(unsigned long size);
74921+void *acl_alloc(unsigned long len);
74922+void *acl_alloc_num(unsigned long num, unsigned long len);
74923+
74924+#endif
74925diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
74926new file mode 100644
74927index 0000000..be66033
74928--- /dev/null
74929+++ b/include/linux/grdefs.h
74930@@ -0,0 +1,140 @@
74931+#ifndef GRDEFS_H
74932+#define GRDEFS_H
74933+
74934+/* Begin grsecurity status declarations */
74935+
74936+enum {
74937+ GR_READY = 0x01,
74938+ GR_STATUS_INIT = 0x00 // disabled state
74939+};
74940+
74941+/* Begin ACL declarations */
74942+
74943+/* Role flags */
74944+
74945+enum {
74946+ GR_ROLE_USER = 0x0001,
74947+ GR_ROLE_GROUP = 0x0002,
74948+ GR_ROLE_DEFAULT = 0x0004,
74949+ GR_ROLE_SPECIAL = 0x0008,
74950+ GR_ROLE_AUTH = 0x0010,
74951+ GR_ROLE_NOPW = 0x0020,
74952+ GR_ROLE_GOD = 0x0040,
74953+ GR_ROLE_LEARN = 0x0080,
74954+ GR_ROLE_TPE = 0x0100,
74955+ GR_ROLE_DOMAIN = 0x0200,
74956+ GR_ROLE_PAM = 0x0400,
74957+ GR_ROLE_PERSIST = 0x0800
74958+};
74959+
74960+/* ACL Subject and Object mode flags */
74961+enum {
74962+ GR_DELETED = 0x80000000
74963+};
74964+
74965+/* ACL Object-only mode flags */
74966+enum {
74967+ GR_READ = 0x00000001,
74968+ GR_APPEND = 0x00000002,
74969+ GR_WRITE = 0x00000004,
74970+ GR_EXEC = 0x00000008,
74971+ GR_FIND = 0x00000010,
74972+ GR_INHERIT = 0x00000020,
74973+ GR_SETID = 0x00000040,
74974+ GR_CREATE = 0x00000080,
74975+ GR_DELETE = 0x00000100,
74976+ GR_LINK = 0x00000200,
74977+ GR_AUDIT_READ = 0x00000400,
74978+ GR_AUDIT_APPEND = 0x00000800,
74979+ GR_AUDIT_WRITE = 0x00001000,
74980+ GR_AUDIT_EXEC = 0x00002000,
74981+ GR_AUDIT_FIND = 0x00004000,
74982+ GR_AUDIT_INHERIT= 0x00008000,
74983+ GR_AUDIT_SETID = 0x00010000,
74984+ GR_AUDIT_CREATE = 0x00020000,
74985+ GR_AUDIT_DELETE = 0x00040000,
74986+ GR_AUDIT_LINK = 0x00080000,
74987+ GR_PTRACERD = 0x00100000,
74988+ GR_NOPTRACE = 0x00200000,
74989+ GR_SUPPRESS = 0x00400000,
74990+ GR_NOLEARN = 0x00800000,
74991+ GR_INIT_TRANSFER= 0x01000000
74992+};
74993+
74994+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
74995+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
74996+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
74997+
74998+/* ACL subject-only mode flags */
74999+enum {
75000+ GR_KILL = 0x00000001,
75001+ GR_VIEW = 0x00000002,
75002+ GR_PROTECTED = 0x00000004,
75003+ GR_LEARN = 0x00000008,
75004+ GR_OVERRIDE = 0x00000010,
75005+ /* just a placeholder, this mode is only used in userspace */
75006+ GR_DUMMY = 0x00000020,
75007+ GR_PROTSHM = 0x00000040,
75008+ GR_KILLPROC = 0x00000080,
75009+ GR_KILLIPPROC = 0x00000100,
75010+ /* just a placeholder, this mode is only used in userspace */
75011+ GR_NOTROJAN = 0x00000200,
75012+ GR_PROTPROCFD = 0x00000400,
75013+ GR_PROCACCT = 0x00000800,
75014+ GR_RELAXPTRACE = 0x00001000,
75015+ //GR_NESTED = 0x00002000,
75016+ GR_INHERITLEARN = 0x00004000,
75017+ GR_PROCFIND = 0x00008000,
75018+ GR_POVERRIDE = 0x00010000,
75019+ GR_KERNELAUTH = 0x00020000,
75020+ GR_ATSECURE = 0x00040000,
75021+ GR_SHMEXEC = 0x00080000
75022+};
75023+
75024+enum {
75025+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
75026+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
75027+ GR_PAX_ENABLE_MPROTECT = 0x0004,
75028+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
75029+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
75030+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
75031+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
75032+ GR_PAX_DISABLE_MPROTECT = 0x0400,
75033+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
75034+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
75035+};
75036+
75037+enum {
75038+ GR_ID_USER = 0x01,
75039+ GR_ID_GROUP = 0x02,
75040+};
75041+
75042+enum {
75043+ GR_ID_ALLOW = 0x01,
75044+ GR_ID_DENY = 0x02,
75045+};
75046+
75047+#define GR_CRASH_RES 31
75048+#define GR_UIDTABLE_MAX 500
75049+
75050+/* begin resource learning section */
75051+enum {
75052+ GR_RLIM_CPU_BUMP = 60,
75053+ GR_RLIM_FSIZE_BUMP = 50000,
75054+ GR_RLIM_DATA_BUMP = 10000,
75055+ GR_RLIM_STACK_BUMP = 1000,
75056+ GR_RLIM_CORE_BUMP = 10000,
75057+ GR_RLIM_RSS_BUMP = 500000,
75058+ GR_RLIM_NPROC_BUMP = 1,
75059+ GR_RLIM_NOFILE_BUMP = 5,
75060+ GR_RLIM_MEMLOCK_BUMP = 50000,
75061+ GR_RLIM_AS_BUMP = 500000,
75062+ GR_RLIM_LOCKS_BUMP = 2,
75063+ GR_RLIM_SIGPENDING_BUMP = 5,
75064+ GR_RLIM_MSGQUEUE_BUMP = 10000,
75065+ GR_RLIM_NICE_BUMP = 1,
75066+ GR_RLIM_RTPRIO_BUMP = 1,
75067+ GR_RLIM_RTTIME_BUMP = 1000000
75068+};
75069+
75070+#endif
75071diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
75072new file mode 100644
75073index 0000000..e337683
75074--- /dev/null
75075+++ b/include/linux/grinternal.h
75076@@ -0,0 +1,229 @@
75077+#ifndef __GRINTERNAL_H
75078+#define __GRINTERNAL_H
75079+
75080+#ifdef CONFIG_GRKERNSEC
75081+
75082+#include <linux/fs.h>
75083+#include <linux/mnt_namespace.h>
75084+#include <linux/nsproxy.h>
75085+#include <linux/gracl.h>
75086+#include <linux/grdefs.h>
75087+#include <linux/grmsg.h>
75088+
75089+void gr_add_learn_entry(const char *fmt, ...)
75090+ __attribute__ ((format (printf, 1, 2)));
75091+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
75092+ const struct vfsmount *mnt);
75093+__u32 gr_check_create(const struct dentry *new_dentry,
75094+ const struct dentry *parent,
75095+ const struct vfsmount *mnt, const __u32 mode);
75096+int gr_check_protected_task(const struct task_struct *task);
75097+__u32 to_gr_audit(const __u32 reqmode);
75098+int gr_set_acls(const int type);
75099+int gr_apply_subject_to_task(struct task_struct *task);
75100+int gr_acl_is_enabled(void);
75101+char gr_roletype_to_char(void);
75102+
75103+void gr_handle_alertkill(struct task_struct *task);
75104+char *gr_to_filename(const struct dentry *dentry,
75105+ const struct vfsmount *mnt);
75106+char *gr_to_filename1(const struct dentry *dentry,
75107+ const struct vfsmount *mnt);
75108+char *gr_to_filename2(const struct dentry *dentry,
75109+ const struct vfsmount *mnt);
75110+char *gr_to_filename3(const struct dentry *dentry,
75111+ const struct vfsmount *mnt);
75112+
75113+extern int grsec_enable_ptrace_readexec;
75114+extern int grsec_enable_harden_ptrace;
75115+extern int grsec_enable_link;
75116+extern int grsec_enable_fifo;
75117+extern int grsec_enable_execve;
75118+extern int grsec_enable_shm;
75119+extern int grsec_enable_execlog;
75120+extern int grsec_enable_signal;
75121+extern int grsec_enable_audit_ptrace;
75122+extern int grsec_enable_forkfail;
75123+extern int grsec_enable_time;
75124+extern int grsec_enable_rofs;
75125+extern int grsec_deny_new_usb;
75126+extern int grsec_enable_chroot_shmat;
75127+extern int grsec_enable_chroot_mount;
75128+extern int grsec_enable_chroot_double;
75129+extern int grsec_enable_chroot_pivot;
75130+extern int grsec_enable_chroot_chdir;
75131+extern int grsec_enable_chroot_chmod;
75132+extern int grsec_enable_chroot_mknod;
75133+extern int grsec_enable_chroot_fchdir;
75134+extern int grsec_enable_chroot_nice;
75135+extern int grsec_enable_chroot_execlog;
75136+extern int grsec_enable_chroot_caps;
75137+extern int grsec_enable_chroot_sysctl;
75138+extern int grsec_enable_chroot_unix;
75139+extern int grsec_enable_symlinkown;
75140+extern kgid_t grsec_symlinkown_gid;
75141+extern int grsec_enable_tpe;
75142+extern kgid_t grsec_tpe_gid;
75143+extern int grsec_enable_tpe_all;
75144+extern int grsec_enable_tpe_invert;
75145+extern int grsec_enable_socket_all;
75146+extern kgid_t grsec_socket_all_gid;
75147+extern int grsec_enable_socket_client;
75148+extern kgid_t grsec_socket_client_gid;
75149+extern int grsec_enable_socket_server;
75150+extern kgid_t grsec_socket_server_gid;
75151+extern kgid_t grsec_audit_gid;
75152+extern int grsec_enable_group;
75153+extern int grsec_enable_log_rwxmaps;
75154+extern int grsec_enable_mount;
75155+extern int grsec_enable_chdir;
75156+extern int grsec_resource_logging;
75157+extern int grsec_enable_blackhole;
75158+extern int grsec_lastack_retries;
75159+extern int grsec_enable_brute;
75160+extern int grsec_lock;
75161+
75162+extern spinlock_t grsec_alert_lock;
75163+extern unsigned long grsec_alert_wtime;
75164+extern unsigned long grsec_alert_fyet;
75165+
75166+extern spinlock_t grsec_audit_lock;
75167+
75168+extern rwlock_t grsec_exec_file_lock;
75169+
75170+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
75171+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
75172+ (tsk)->exec_file->f_path.mnt) : "/")
75173+
75174+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
75175+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
75176+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75177+
75178+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
75179+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
75180+ (tsk)->exec_file->f_path.mnt) : "/")
75181+
75182+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
75183+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
75184+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
75185+
75186+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
75187+
75188+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
75189+
75190+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
75191+{
75192+ if (file1 && file2) {
75193+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
75194+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
75195+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
75196+ return true;
75197+ }
75198+
75199+ return false;
75200+}
75201+
75202+#define GR_CHROOT_CAPS {{ \
75203+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
75204+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
75205+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
75206+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
75207+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
75208+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
75209+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
75210+
75211+#define security_learn(normal_msg,args...) \
75212+({ \
75213+ read_lock(&grsec_exec_file_lock); \
75214+ gr_add_learn_entry(normal_msg "\n", ## args); \
75215+ read_unlock(&grsec_exec_file_lock); \
75216+})
75217+
75218+enum {
75219+ GR_DO_AUDIT,
75220+ GR_DONT_AUDIT,
75221+ /* used for non-audit messages that we shouldn't kill the task on */
75222+ GR_DONT_AUDIT_GOOD
75223+};
75224+
75225+enum {
75226+ GR_TTYSNIFF,
75227+ GR_RBAC,
75228+ GR_RBAC_STR,
75229+ GR_STR_RBAC,
75230+ GR_RBAC_MODE2,
75231+ GR_RBAC_MODE3,
75232+ GR_FILENAME,
75233+ GR_SYSCTL_HIDDEN,
75234+ GR_NOARGS,
75235+ GR_ONE_INT,
75236+ GR_ONE_INT_TWO_STR,
75237+ GR_ONE_STR,
75238+ GR_STR_INT,
75239+ GR_TWO_STR_INT,
75240+ GR_TWO_INT,
75241+ GR_TWO_U64,
75242+ GR_THREE_INT,
75243+ GR_FIVE_INT_TWO_STR,
75244+ GR_TWO_STR,
75245+ GR_THREE_STR,
75246+ GR_FOUR_STR,
75247+ GR_STR_FILENAME,
75248+ GR_FILENAME_STR,
75249+ GR_FILENAME_TWO_INT,
75250+ GR_FILENAME_TWO_INT_STR,
75251+ GR_TEXTREL,
75252+ GR_PTRACE,
75253+ GR_RESOURCE,
75254+ GR_CAP,
75255+ GR_SIG,
75256+ GR_SIG2,
75257+ GR_CRASH1,
75258+ GR_CRASH2,
75259+ GR_PSACCT,
75260+ GR_RWXMAP,
75261+ GR_RWXMAPVMA
75262+};
75263+
75264+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
75265+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
75266+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
75267+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
75268+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
75269+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
75270+#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)
75271+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
75272+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
75273+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
75274+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
75275+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
75276+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
75277+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
75278+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
75279+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
75280+#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)
75281+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
75282+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
75283+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
75284+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
75285+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
75286+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
75287+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
75288+#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)
75289+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
75290+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
75291+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
75292+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
75293+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
75294+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
75295+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
75296+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
75297+#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)
75298+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
75299+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
75300+
75301+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
75302+
75303+#endif
75304+
75305+#endif
75306diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
75307new file mode 100644
75308index 0000000..a4396b5
75309--- /dev/null
75310+++ b/include/linux/grmsg.h
75311@@ -0,0 +1,113 @@
75312+#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"
75313+#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"
75314+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
75315+#define GR_STOPMOD_MSG "denied modification of module state by "
75316+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
75317+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
75318+#define GR_IOPERM_MSG "denied use of ioperm() by "
75319+#define GR_IOPL_MSG "denied use of iopl() by "
75320+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
75321+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
75322+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
75323+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
75324+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
75325+#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"
75326+#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"
75327+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
75328+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
75329+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
75330+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
75331+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
75332+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
75333+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
75334+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
75335+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
75336+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
75337+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
75338+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
75339+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
75340+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
75341+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
75342+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
75343+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
75344+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
75345+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
75346+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
75347+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
75348+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
75349+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
75350+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
75351+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
75352+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
75353+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
75354+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
75355+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
75356+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
75357+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
75358+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
75359+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
75360+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
75361+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
75362+#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"
75363+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
75364+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
75365+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
75366+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
75367+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
75368+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
75369+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
75370+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
75371+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
75372+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
75373+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
75374+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
75375+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
75376+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
75377+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
75378+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
75379+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
75380+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
75381+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
75382+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
75383+#define GR_FAILFORK_MSG "failed fork with errno %s by "
75384+#define GR_NICE_CHROOT_MSG "denied priority change by "
75385+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
75386+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
75387+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
75388+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
75389+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
75390+#define GR_TIME_MSG "time set by "
75391+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
75392+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
75393+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
75394+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
75395+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
75396+#define GR_BIND_MSG "denied bind() by "
75397+#define GR_CONNECT_MSG "denied connect() by "
75398+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
75399+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
75400+#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"
75401+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
75402+#define GR_CAP_ACL_MSG "use of %s denied for "
75403+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
75404+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
75405+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
75406+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
75407+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
75408+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
75409+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
75410+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
75411+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
75412+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
75413+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
75414+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
75415+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
75416+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
75417+#define GR_VM86_MSG "denied use of vm86 by "
75418+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
75419+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
75420+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
75421+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
75422+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
75423+#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 "
75424+#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 "
75425diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
75426new file mode 100644
75427index 0000000..d6f5a21
75428--- /dev/null
75429+++ b/include/linux/grsecurity.h
75430@@ -0,0 +1,244 @@
75431+#ifndef GR_SECURITY_H
75432+#define GR_SECURITY_H
75433+#include <linux/fs.h>
75434+#include <linux/fs_struct.h>
75435+#include <linux/binfmts.h>
75436+#include <linux/gracl.h>
75437+
75438+/* notify of brain-dead configs */
75439+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75440+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
75441+#endif
75442+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
75443+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
75444+#endif
75445+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
75446+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
75447+#endif
75448+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
75449+#error "CONFIG_PAX enabled, but no PaX options are enabled."
75450+#endif
75451+
75452+int gr_handle_new_usb(void);
75453+
75454+void gr_handle_brute_attach(unsigned long mm_flags);
75455+void gr_handle_brute_check(void);
75456+void gr_handle_kernel_exploit(void);
75457+
75458+char gr_roletype_to_char(void);
75459+
75460+int gr_acl_enable_at_secure(void);
75461+
75462+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
75463+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
75464+
75465+void gr_del_task_from_ip_table(struct task_struct *p);
75466+
75467+int gr_pid_is_chrooted(struct task_struct *p);
75468+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
75469+int gr_handle_chroot_nice(void);
75470+int gr_handle_chroot_sysctl(const int op);
75471+int gr_handle_chroot_setpriority(struct task_struct *p,
75472+ const int niceval);
75473+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
75474+int gr_handle_chroot_chroot(const struct dentry *dentry,
75475+ const struct vfsmount *mnt);
75476+void gr_handle_chroot_chdir(const struct path *path);
75477+int gr_handle_chroot_chmod(const struct dentry *dentry,
75478+ const struct vfsmount *mnt, const int mode);
75479+int gr_handle_chroot_mknod(const struct dentry *dentry,
75480+ const struct vfsmount *mnt, const int mode);
75481+int gr_handle_chroot_mount(const struct dentry *dentry,
75482+ const struct vfsmount *mnt,
75483+ const char *dev_name);
75484+int gr_handle_chroot_pivot(void);
75485+int gr_handle_chroot_unix(const pid_t pid);
75486+
75487+int gr_handle_rawio(const struct inode *inode);
75488+
75489+void gr_handle_ioperm(void);
75490+void gr_handle_iopl(void);
75491+
75492+umode_t gr_acl_umask(void);
75493+
75494+int gr_tpe_allow(const struct file *file);
75495+
75496+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
75497+void gr_clear_chroot_entries(struct task_struct *task);
75498+
75499+void gr_log_forkfail(const int retval);
75500+void gr_log_timechange(void);
75501+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
75502+void gr_log_chdir(const struct dentry *dentry,
75503+ const struct vfsmount *mnt);
75504+void gr_log_chroot_exec(const struct dentry *dentry,
75505+ const struct vfsmount *mnt);
75506+void gr_log_remount(const char *devname, const int retval);
75507+void gr_log_unmount(const char *devname, const int retval);
75508+void gr_log_mount(const char *from, const char *to, const int retval);
75509+void gr_log_textrel(struct vm_area_struct *vma);
75510+void gr_log_ptgnustack(struct file *file);
75511+void gr_log_rwxmmap(struct file *file);
75512+void gr_log_rwxmprotect(struct vm_area_struct *vma);
75513+
75514+int gr_handle_follow_link(const struct inode *parent,
75515+ const struct inode *inode,
75516+ const struct dentry *dentry,
75517+ const struct vfsmount *mnt);
75518+int gr_handle_fifo(const struct dentry *dentry,
75519+ const struct vfsmount *mnt,
75520+ const struct dentry *dir, const int flag,
75521+ const int acc_mode);
75522+int gr_handle_hardlink(const struct dentry *dentry,
75523+ const struct vfsmount *mnt,
75524+ struct inode *inode,
75525+ const int mode, const struct filename *to);
75526+
75527+int gr_is_capable(const int cap);
75528+int gr_is_capable_nolog(const int cap);
75529+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
75530+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
75531+
75532+void gr_copy_label(struct task_struct *tsk);
75533+void gr_handle_crash(struct task_struct *task, const int sig);
75534+int gr_handle_signal(const struct task_struct *p, const int sig);
75535+int gr_check_crash_uid(const kuid_t uid);
75536+int gr_check_protected_task(const struct task_struct *task);
75537+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
75538+int gr_acl_handle_mmap(const struct file *file,
75539+ const unsigned long prot);
75540+int gr_acl_handle_mprotect(const struct file *file,
75541+ const unsigned long prot);
75542+int gr_check_hidden_task(const struct task_struct *tsk);
75543+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
75544+ const struct vfsmount *mnt);
75545+__u32 gr_acl_handle_utime(const struct dentry *dentry,
75546+ const struct vfsmount *mnt);
75547+__u32 gr_acl_handle_access(const struct dentry *dentry,
75548+ const struct vfsmount *mnt, const int fmode);
75549+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
75550+ const struct vfsmount *mnt, umode_t *mode);
75551+__u32 gr_acl_handle_chown(const struct dentry *dentry,
75552+ const struct vfsmount *mnt);
75553+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
75554+ const struct vfsmount *mnt);
75555+int gr_handle_ptrace(struct task_struct *task, const long request);
75556+int gr_handle_proc_ptrace(struct task_struct *task);
75557+__u32 gr_acl_handle_execve(const struct dentry *dentry,
75558+ const struct vfsmount *mnt);
75559+int gr_check_crash_exec(const struct file *filp);
75560+int gr_acl_is_enabled(void);
75561+void gr_set_kernel_label(struct task_struct *task);
75562+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
75563+ const kgid_t gid);
75564+int gr_set_proc_label(const struct dentry *dentry,
75565+ const struct vfsmount *mnt,
75566+ const int unsafe_flags);
75567+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
75568+ const struct vfsmount *mnt);
75569+__u32 gr_acl_handle_open(const struct dentry *dentry,
75570+ const struct vfsmount *mnt, int acc_mode);
75571+__u32 gr_acl_handle_creat(const struct dentry *dentry,
75572+ const struct dentry *p_dentry,
75573+ const struct vfsmount *p_mnt,
75574+ int open_flags, int acc_mode, const int imode);
75575+void gr_handle_create(const struct dentry *dentry,
75576+ const struct vfsmount *mnt);
75577+void gr_handle_proc_create(const struct dentry *dentry,
75578+ const struct inode *inode);
75579+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
75580+ const struct dentry *parent_dentry,
75581+ const struct vfsmount *parent_mnt,
75582+ const int mode);
75583+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
75584+ const struct dentry *parent_dentry,
75585+ const struct vfsmount *parent_mnt);
75586+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
75587+ const struct vfsmount *mnt);
75588+void gr_handle_delete(const ino_t ino, const dev_t dev);
75589+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
75590+ const struct vfsmount *mnt);
75591+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
75592+ const struct dentry *parent_dentry,
75593+ const struct vfsmount *parent_mnt,
75594+ const struct filename *from);
75595+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
75596+ const struct dentry *parent_dentry,
75597+ const struct vfsmount *parent_mnt,
75598+ const struct dentry *old_dentry,
75599+ const struct vfsmount *old_mnt, const struct filename *to);
75600+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
75601+int gr_acl_handle_rename(struct dentry *new_dentry,
75602+ struct dentry *parent_dentry,
75603+ const struct vfsmount *parent_mnt,
75604+ struct dentry *old_dentry,
75605+ struct inode *old_parent_inode,
75606+ struct vfsmount *old_mnt, const struct filename *newname);
75607+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
75608+ struct dentry *old_dentry,
75609+ struct dentry *new_dentry,
75610+ struct vfsmount *mnt, const __u8 replace);
75611+__u32 gr_check_link(const struct dentry *new_dentry,
75612+ const struct dentry *parent_dentry,
75613+ const struct vfsmount *parent_mnt,
75614+ const struct dentry *old_dentry,
75615+ const struct vfsmount *old_mnt);
75616+int gr_acl_handle_filldir(const struct file *file, const char *name,
75617+ const unsigned int namelen, const ino_t ino);
75618+
75619+__u32 gr_acl_handle_unix(const struct dentry *dentry,
75620+ const struct vfsmount *mnt);
75621+void gr_acl_handle_exit(void);
75622+void gr_acl_handle_psacct(struct task_struct *task, const long code);
75623+int gr_acl_handle_procpidmem(const struct task_struct *task);
75624+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
75625+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
75626+void gr_audit_ptrace(struct task_struct *task);
75627+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
75628+void gr_put_exec_file(struct task_struct *task);
75629+
75630+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
75631+
75632+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
75633+extern void gr_learn_resource(const struct task_struct *task, const int res,
75634+ const unsigned long wanted, const int gt);
75635+#else
75636+static inline void gr_learn_resource(const struct task_struct *task, const int res,
75637+ const unsigned long wanted, const int gt)
75638+{
75639+}
75640+#endif
75641+
75642+#ifdef CONFIG_GRKERNSEC_RESLOG
75643+extern void gr_log_resource(const struct task_struct *task, const int res,
75644+ const unsigned long wanted, const int gt);
75645+#else
75646+static inline void gr_log_resource(const struct task_struct *task, const int res,
75647+ const unsigned long wanted, const int gt)
75648+{
75649+}
75650+#endif
75651+
75652+#ifdef CONFIG_GRKERNSEC
75653+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
75654+void gr_handle_vm86(void);
75655+void gr_handle_mem_readwrite(u64 from, u64 to);
75656+
75657+void gr_log_badprocpid(const char *entry);
75658+
75659+extern int grsec_enable_dmesg;
75660+extern int grsec_disable_privio;
75661+
75662+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75663+extern kgid_t grsec_proc_gid;
75664+#endif
75665+
75666+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75667+extern int grsec_enable_chroot_findtask;
75668+#endif
75669+#ifdef CONFIG_GRKERNSEC_SETXID
75670+extern int grsec_enable_setxid;
75671+#endif
75672+#endif
75673+
75674+#endif
75675diff --git a/include/linux/grsock.h b/include/linux/grsock.h
75676new file mode 100644
75677index 0000000..e7ffaaf
75678--- /dev/null
75679+++ b/include/linux/grsock.h
75680@@ -0,0 +1,19 @@
75681+#ifndef __GRSOCK_H
75682+#define __GRSOCK_H
75683+
75684+extern void gr_attach_curr_ip(const struct sock *sk);
75685+extern int gr_handle_sock_all(const int family, const int type,
75686+ const int protocol);
75687+extern int gr_handle_sock_server(const struct sockaddr *sck);
75688+extern int gr_handle_sock_server_other(const struct sock *sck);
75689+extern int gr_handle_sock_client(const struct sockaddr *sck);
75690+extern int gr_search_connect(struct socket * sock,
75691+ struct sockaddr_in * addr);
75692+extern int gr_search_bind(struct socket * sock,
75693+ struct sockaddr_in * addr);
75694+extern int gr_search_listen(struct socket * sock);
75695+extern int gr_search_accept(struct socket * sock);
75696+extern int gr_search_socket(const int domain, const int type,
75697+ const int protocol);
75698+
75699+#endif
75700diff --git a/include/linux/hid.h b/include/linux/hid.h
75701index 0c48991..76e41d8 100644
75702--- a/include/linux/hid.h
75703+++ b/include/linux/hid.h
75704@@ -393,10 +393,12 @@ struct hid_report {
75705 struct hid_device *device; /* associated device */
75706 };
75707
75708+#define HID_MAX_IDS 256
75709+
75710 struct hid_report_enum {
75711 unsigned numbered;
75712 struct list_head report_list;
75713- struct hid_report *report_id_hash[256];
75714+ struct hid_report *report_id_hash[HID_MAX_IDS];
75715 };
75716
75717 #define HID_REPORT_TYPES 3
75718@@ -747,6 +749,10 @@ void hid_output_report(struct hid_report *report, __u8 *data);
75719 struct hid_device *hid_allocate_device(void);
75720 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
75721 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
75722+struct hid_report *hid_validate_report(struct hid_device *hid,
75723+ unsigned int type, unsigned int id,
75724+ unsigned int fields,
75725+ unsigned int report_counts);
75726 int hid_open_report(struct hid_device *device);
75727 int hid_check_keys_pressed(struct hid_device *hid);
75728 int hid_connect(struct hid_device *hid, unsigned int connect_mask);
75729diff --git a/include/linux/highmem.h b/include/linux/highmem.h
75730index 7fb31da..08b5114 100644
75731--- a/include/linux/highmem.h
75732+++ b/include/linux/highmem.h
75733@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
75734 kunmap_atomic(kaddr);
75735 }
75736
75737+static inline void sanitize_highpage(struct page *page)
75738+{
75739+ void *kaddr;
75740+ unsigned long flags;
75741+
75742+ local_irq_save(flags);
75743+ kaddr = kmap_atomic(page);
75744+ clear_page(kaddr);
75745+ kunmap_atomic(kaddr);
75746+ local_irq_restore(flags);
75747+}
75748+
75749 static inline void zero_user_segments(struct page *page,
75750 unsigned start1, unsigned end1,
75751 unsigned start2, unsigned end2)
75752diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
75753index 1c7b89a..7f52502 100644
75754--- a/include/linux/hwmon-sysfs.h
75755+++ b/include/linux/hwmon-sysfs.h
75756@@ -25,7 +25,8 @@
75757 struct sensor_device_attribute{
75758 struct device_attribute dev_attr;
75759 int index;
75760-};
75761+} __do_const;
75762+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
75763 #define to_sensor_dev_attr(_dev_attr) \
75764 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
75765
75766@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
75767 struct device_attribute dev_attr;
75768 u8 index;
75769 u8 nr;
75770-};
75771+} __do_const;
75772 #define to_sensor_dev_attr_2(_dev_attr) \
75773 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
75774
75775diff --git a/include/linux/i2c.h b/include/linux/i2c.h
75776index e988fa9..ff9f17e 100644
75777--- a/include/linux/i2c.h
75778+++ b/include/linux/i2c.h
75779@@ -366,6 +366,7 @@ struct i2c_algorithm {
75780 /* To determine what the adapter supports */
75781 u32 (*functionality) (struct i2c_adapter *);
75782 };
75783+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
75784
75785 /**
75786 * struct i2c_bus_recovery_info - I2C bus recovery information
75787diff --git a/include/linux/i2o.h b/include/linux/i2o.h
75788index d23c3c2..eb63c81 100644
75789--- a/include/linux/i2o.h
75790+++ b/include/linux/i2o.h
75791@@ -565,7 +565,7 @@ struct i2o_controller {
75792 struct i2o_device *exec; /* Executive */
75793 #if BITS_PER_LONG == 64
75794 spinlock_t context_list_lock; /* lock for context_list */
75795- atomic_t context_list_counter; /* needed for unique contexts */
75796+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
75797 struct list_head context_list; /* list of context id's
75798 and pointers */
75799 #endif
75800diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
75801index aff7ad8..3942bbd 100644
75802--- a/include/linux/if_pppox.h
75803+++ b/include/linux/if_pppox.h
75804@@ -76,7 +76,7 @@ struct pppox_proto {
75805 int (*ioctl)(struct socket *sock, unsigned int cmd,
75806 unsigned long arg);
75807 struct module *owner;
75808-};
75809+} __do_const;
75810
75811 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
75812 extern void unregister_pppox_proto(int proto_num);
75813diff --git a/include/linux/init.h b/include/linux/init.h
75814index 8618147..0821126 100644
75815--- a/include/linux/init.h
75816+++ b/include/linux/init.h
75817@@ -39,9 +39,36 @@
75818 * Also note, that this data cannot be "const".
75819 */
75820
75821+#ifdef MODULE
75822+#define add_init_latent_entropy
75823+#define add_devinit_latent_entropy
75824+#define add_cpuinit_latent_entropy
75825+#define add_meminit_latent_entropy
75826+#else
75827+#define add_init_latent_entropy __latent_entropy
75828+
75829+#ifdef CONFIG_HOTPLUG
75830+#define add_devinit_latent_entropy
75831+#else
75832+#define add_devinit_latent_entropy __latent_entropy
75833+#endif
75834+
75835+#ifdef CONFIG_HOTPLUG_CPU
75836+#define add_cpuinit_latent_entropy
75837+#else
75838+#define add_cpuinit_latent_entropy __latent_entropy
75839+#endif
75840+
75841+#ifdef CONFIG_MEMORY_HOTPLUG
75842+#define add_meminit_latent_entropy
75843+#else
75844+#define add_meminit_latent_entropy __latent_entropy
75845+#endif
75846+#endif
75847+
75848 /* These are for everybody (although not all archs will actually
75849 discard it in modules) */
75850-#define __init __section(.init.text) __cold notrace
75851+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
75852 #define __initdata __section(.init.data)
75853 #define __initconst __constsection(.init.rodata)
75854 #define __exitdata __section(.exit.data)
75855@@ -94,7 +121,7 @@
75856 #define __exit __section(.exit.text) __exitused __cold notrace
75857
75858 /* Used for HOTPLUG_CPU */
75859-#define __cpuinit __section(.cpuinit.text) __cold notrace
75860+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
75861 #define __cpuinitdata __section(.cpuinit.data)
75862 #define __cpuinitconst __constsection(.cpuinit.rodata)
75863 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
75864@@ -102,7 +129,7 @@
75865 #define __cpuexitconst __constsection(.cpuexit.rodata)
75866
75867 /* Used for MEMORY_HOTPLUG */
75868-#define __meminit __section(.meminit.text) __cold notrace
75869+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
75870 #define __meminitdata __section(.meminit.data)
75871 #define __meminitconst __constsection(.meminit.rodata)
75872 #define __memexit __section(.memexit.text) __exitused __cold notrace
75873diff --git a/include/linux/init_task.h b/include/linux/init_task.h
75874index 5cd0f09..c9f67cc 100644
75875--- a/include/linux/init_task.h
75876+++ b/include/linux/init_task.h
75877@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
75878
75879 #define INIT_TASK_COMM "swapper"
75880
75881+#ifdef CONFIG_X86
75882+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
75883+#else
75884+#define INIT_TASK_THREAD_INFO
75885+#endif
75886+
75887 /*
75888 * INIT_TASK is used to set up the first task table, touch at
75889 * your own risk!. Base=0, limit=0x1fffff (=2MB)
75890@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
75891 RCU_POINTER_INITIALIZER(cred, &init_cred), \
75892 .comm = INIT_TASK_COMM, \
75893 .thread = INIT_THREAD, \
75894+ INIT_TASK_THREAD_INFO \
75895 .fs = &init_fs, \
75896 .files = &init_files, \
75897 .signal = &init_signals, \
75898diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
75899index 5fa5afe..ac55b25 100644
75900--- a/include/linux/interrupt.h
75901+++ b/include/linux/interrupt.h
75902@@ -430,7 +430,7 @@ enum
75903 /* map softirq index to softirq name. update 'softirq_to_name' in
75904 * kernel/softirq.c when adding a new softirq.
75905 */
75906-extern char *softirq_to_name[NR_SOFTIRQS];
75907+extern const char * const softirq_to_name[NR_SOFTIRQS];
75908
75909 /* softirq mask and active fields moved to irq_cpustat_t in
75910 * asm/hardirq.h to get better cache usage. KAO
75911@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
75912
75913 struct softirq_action
75914 {
75915- void (*action)(struct softirq_action *);
75916-};
75917+ void (*action)(void);
75918+} __no_const;
75919
75920 asmlinkage void do_softirq(void);
75921 asmlinkage void __do_softirq(void);
75922-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
75923+extern void open_softirq(int nr, void (*action)(void));
75924 extern void softirq_init(void);
75925 extern void __raise_softirq_irqoff(unsigned int nr);
75926
75927diff --git a/include/linux/iommu.h b/include/linux/iommu.h
75928index 3aeb730..2177f39 100644
75929--- a/include/linux/iommu.h
75930+++ b/include/linux/iommu.h
75931@@ -113,7 +113,7 @@ struct iommu_ops {
75932 u32 (*domain_get_windows)(struct iommu_domain *domain);
75933
75934 unsigned long pgsize_bitmap;
75935-};
75936+} __do_const;
75937
75938 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
75939 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
75940diff --git a/include/linux/ioport.h b/include/linux/ioport.h
75941index 89b7c24..382af74 100644
75942--- a/include/linux/ioport.h
75943+++ b/include/linux/ioport.h
75944@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
75945 int adjust_resource(struct resource *res, resource_size_t start,
75946 resource_size_t size);
75947 resource_size_t resource_alignment(struct resource *res);
75948-static inline resource_size_t resource_size(const struct resource *res)
75949+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
75950 {
75951 return res->end - res->start + 1;
75952 }
75953diff --git a/include/linux/irq.h b/include/linux/irq.h
75954index bc4e066..50468a9 100644
75955--- a/include/linux/irq.h
75956+++ b/include/linux/irq.h
75957@@ -328,7 +328,8 @@ struct irq_chip {
75958 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
75959
75960 unsigned long flags;
75961-};
75962+} __do_const;
75963+typedef struct irq_chip __no_const irq_chip_no_const;
75964
75965 /*
75966 * irq_chip specific flags
75967diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
75968index 3e203eb..3fe68d0 100644
75969--- a/include/linux/irqchip/arm-gic.h
75970+++ b/include/linux/irqchip/arm-gic.h
75971@@ -59,9 +59,11 @@
75972
75973 #ifndef __ASSEMBLY__
75974
75975+#include <linux/irq.h>
75976+
75977 struct device_node;
75978
75979-extern struct irq_chip gic_arch_extn;
75980+extern irq_chip_no_const gic_arch_extn;
75981
75982 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
75983 u32 offset, struct device_node *);
75984diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
75985index 6883e19..e854fcb 100644
75986--- a/include/linux/kallsyms.h
75987+++ b/include/linux/kallsyms.h
75988@@ -15,7 +15,8 @@
75989
75990 struct module;
75991
75992-#ifdef CONFIG_KALLSYMS
75993+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
75994+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75995 /* Lookup the address for a symbol. Returns 0 if not found. */
75996 unsigned long kallsyms_lookup_name(const char *name);
75997
75998@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
75999 /* Stupid that this does nothing, but I didn't create this mess. */
76000 #define __print_symbol(fmt, addr)
76001 #endif /*CONFIG_KALLSYMS*/
76002+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
76003+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
76004+extern unsigned long kallsyms_lookup_name(const char *name);
76005+extern void __print_symbol(const char *fmt, unsigned long address);
76006+extern int sprint_backtrace(char *buffer, unsigned long address);
76007+extern int sprint_symbol(char *buffer, unsigned long address);
76008+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
76009+const char *kallsyms_lookup(unsigned long addr,
76010+ unsigned long *symbolsize,
76011+ unsigned long *offset,
76012+ char **modname, char *namebuf);
76013+extern int kallsyms_lookup_size_offset(unsigned long addr,
76014+ unsigned long *symbolsize,
76015+ unsigned long *offset);
76016+#endif
76017
76018 /* This macro allows us to keep printk typechecking */
76019 static __printf(1, 2)
76020diff --git a/include/linux/key-type.h b/include/linux/key-type.h
76021index 518a53a..5e28358 100644
76022--- a/include/linux/key-type.h
76023+++ b/include/linux/key-type.h
76024@@ -125,7 +125,7 @@ struct key_type {
76025 /* internal fields */
76026 struct list_head link; /* link in types list */
76027 struct lock_class_key lock_class; /* key->sem lock class */
76028-};
76029+} __do_const;
76030
76031 extern struct key_type key_type_keyring;
76032
76033diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
76034index c6e091b..a940adf 100644
76035--- a/include/linux/kgdb.h
76036+++ b/include/linux/kgdb.h
76037@@ -52,7 +52,7 @@ extern int kgdb_connected;
76038 extern int kgdb_io_module_registered;
76039
76040 extern atomic_t kgdb_setting_breakpoint;
76041-extern atomic_t kgdb_cpu_doing_single_step;
76042+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
76043
76044 extern struct task_struct *kgdb_usethread;
76045 extern struct task_struct *kgdb_contthread;
76046@@ -254,7 +254,7 @@ struct kgdb_arch {
76047 void (*correct_hw_break)(void);
76048
76049 void (*enable_nmi)(bool on);
76050-};
76051+} __do_const;
76052
76053 /**
76054 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
76055@@ -279,7 +279,7 @@ struct kgdb_io {
76056 void (*pre_exception) (void);
76057 void (*post_exception) (void);
76058 int is_console;
76059-};
76060+} __do_const;
76061
76062 extern struct kgdb_arch arch_kgdb_ops;
76063
76064diff --git a/include/linux/kmod.h b/include/linux/kmod.h
76065index 0555cc6..b16a7a4 100644
76066--- a/include/linux/kmod.h
76067+++ b/include/linux/kmod.h
76068@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
76069 * usually useless though. */
76070 extern __printf(2, 3)
76071 int __request_module(bool wait, const char *name, ...);
76072+extern __printf(3, 4)
76073+int ___request_module(bool wait, char *param_name, const char *name, ...);
76074 #define request_module(mod...) __request_module(true, mod)
76075 #define request_module_nowait(mod...) __request_module(false, mod)
76076 #define try_then_request_module(x, mod...) \
76077diff --git a/include/linux/kobject.h b/include/linux/kobject.h
76078index 939b112..ed6ed51 100644
76079--- a/include/linux/kobject.h
76080+++ b/include/linux/kobject.h
76081@@ -111,7 +111,7 @@ struct kobj_type {
76082 struct attribute **default_attrs;
76083 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
76084 const void *(*namespace)(struct kobject *kobj);
76085-};
76086+} __do_const;
76087
76088 struct kobj_uevent_env {
76089 char *envp[UEVENT_NUM_ENVP];
76090@@ -134,6 +134,7 @@ struct kobj_attribute {
76091 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
76092 const char *buf, size_t count);
76093 };
76094+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
76095
76096 extern const struct sysfs_ops kobj_sysfs_ops;
76097
76098diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
76099index f66b065..c2c29b4 100644
76100--- a/include/linux/kobject_ns.h
76101+++ b/include/linux/kobject_ns.h
76102@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
76103 const void *(*netlink_ns)(struct sock *sk);
76104 const void *(*initial_ns)(void);
76105 void (*drop_ns)(void *);
76106-};
76107+} __do_const;
76108
76109 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
76110 int kobj_ns_type_registered(enum kobj_ns_type type);
76111diff --git a/include/linux/kref.h b/include/linux/kref.h
76112index 484604d..0f6c5b6 100644
76113--- a/include/linux/kref.h
76114+++ b/include/linux/kref.h
76115@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
76116 static inline int kref_sub(struct kref *kref, unsigned int count,
76117 void (*release)(struct kref *kref))
76118 {
76119- WARN_ON(release == NULL);
76120+ BUG_ON(release == NULL);
76121
76122 if (atomic_sub_and_test((int) count, &kref->refcount)) {
76123 release(kref);
76124diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
76125index 8db53cf..c21121d 100644
76126--- a/include/linux/kvm_host.h
76127+++ b/include/linux/kvm_host.h
76128@@ -444,7 +444,7 @@ static inline void kvm_irqfd_exit(void)
76129 {
76130 }
76131 #endif
76132-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76133+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
76134 struct module *module);
76135 void kvm_exit(void);
76136
76137@@ -616,7 +616,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
76138 struct kvm_guest_debug *dbg);
76139 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
76140
76141-int kvm_arch_init(void *opaque);
76142+int kvm_arch_init(const void *opaque);
76143 void kvm_arch_exit(void);
76144
76145 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
76146diff --git a/include/linux/libata.h b/include/linux/libata.h
76147index eae7a05..2cdd875 100644
76148--- a/include/linux/libata.h
76149+++ b/include/linux/libata.h
76150@@ -919,7 +919,7 @@ struct ata_port_operations {
76151 * fields must be pointers.
76152 */
76153 const struct ata_port_operations *inherits;
76154-};
76155+} __do_const;
76156
76157 struct ata_port_info {
76158 unsigned long flags;
76159diff --git a/include/linux/list.h b/include/linux/list.h
76160index b83e565..baa6c1d 100644
76161--- a/include/linux/list.h
76162+++ b/include/linux/list.h
76163@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
76164 extern void list_del(struct list_head *entry);
76165 #endif
76166
76167+extern void __pax_list_add(struct list_head *new,
76168+ struct list_head *prev,
76169+ struct list_head *next);
76170+static inline void pax_list_add(struct list_head *new, struct list_head *head)
76171+{
76172+ __pax_list_add(new, head, head->next);
76173+}
76174+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
76175+{
76176+ __pax_list_add(new, head->prev, head);
76177+}
76178+extern void pax_list_del(struct list_head *entry);
76179+
76180 /**
76181 * list_replace - replace old entry by new one
76182 * @old : the element to be replaced
76183@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
76184 INIT_LIST_HEAD(entry);
76185 }
76186
76187+extern void pax_list_del_init(struct list_head *entry);
76188+
76189 /**
76190 * list_move - delete from one list and add as another's head
76191 * @list: the entry to move
76192diff --git a/include/linux/math64.h b/include/linux/math64.h
76193index 2913b86..8dcbb1e 100644
76194--- a/include/linux/math64.h
76195+++ b/include/linux/math64.h
76196@@ -15,7 +15,7 @@
76197 * This is commonly provided by 32bit archs to provide an optimized 64bit
76198 * divide.
76199 */
76200-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76201+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76202 {
76203 *remainder = dividend % divisor;
76204 return dividend / divisor;
76205@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
76206 /**
76207 * div64_u64 - unsigned 64bit divide with 64bit divisor
76208 */
76209-static inline u64 div64_u64(u64 dividend, u64 divisor)
76210+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
76211 {
76212 return dividend / divisor;
76213 }
76214@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
76215 #define div64_ul(x, y) div_u64((x), (y))
76216
76217 #ifndef div_u64_rem
76218-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76219+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
76220 {
76221 *remainder = do_div(dividend, divisor);
76222 return dividend;
76223@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
76224 * divide.
76225 */
76226 #ifndef div_u64
76227-static inline u64 div_u64(u64 dividend, u32 divisor)
76228+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
76229 {
76230 u32 remainder;
76231 return div_u64_rem(dividend, divisor, &remainder);
76232diff --git a/include/linux/mm.h b/include/linux/mm.h
76233index e0c8528..bcf0c29 100644
76234--- a/include/linux/mm.h
76235+++ b/include/linux/mm.h
76236@@ -104,6 +104,11 @@ extern unsigned int kobjsize(const void *objp);
76237 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
76238 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
76239 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
76240+
76241+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76242+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
76243+#endif
76244+
76245 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
76246
76247 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
76248@@ -205,8 +210,8 @@ struct vm_operations_struct {
76249 /* called by access_process_vm when get_user_pages() fails, typically
76250 * for use by special VMAs that can switch between memory and hardware
76251 */
76252- int (*access)(struct vm_area_struct *vma, unsigned long addr,
76253- void *buf, int len, int write);
76254+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
76255+ void *buf, size_t len, int write);
76256 #ifdef CONFIG_NUMA
76257 /*
76258 * set_policy() op must add a reference to any non-NULL @new mempolicy
76259@@ -236,6 +241,7 @@ struct vm_operations_struct {
76260 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
76261 unsigned long size, pgoff_t pgoff);
76262 };
76263+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
76264
76265 struct mmu_gather;
76266 struct inode;
76267@@ -980,8 +986,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
76268 unsigned long *pfn);
76269 int follow_phys(struct vm_area_struct *vma, unsigned long address,
76270 unsigned int flags, unsigned long *prot, resource_size_t *phys);
76271-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76272- void *buf, int len, int write);
76273+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76274+ void *buf, size_t len, int write);
76275
76276 static inline void unmap_shared_mapping_range(struct address_space *mapping,
76277 loff_t const holebegin, loff_t const holelen)
76278@@ -1020,9 +1026,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
76279 }
76280 #endif
76281
76282-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
76283-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
76284- void *buf, int len, int write);
76285+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
76286+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
76287+ void *buf, size_t len, int write);
76288
76289 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76290 unsigned long start, unsigned long nr_pages,
76291@@ -1053,34 +1059,6 @@ int set_page_dirty(struct page *page);
76292 int set_page_dirty_lock(struct page *page);
76293 int clear_page_dirty_for_io(struct page *page);
76294
76295-/* Is the vma a continuation of the stack vma above it? */
76296-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
76297-{
76298- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
76299-}
76300-
76301-static inline int stack_guard_page_start(struct vm_area_struct *vma,
76302- unsigned long addr)
76303-{
76304- return (vma->vm_flags & VM_GROWSDOWN) &&
76305- (vma->vm_start == addr) &&
76306- !vma_growsdown(vma->vm_prev, addr);
76307-}
76308-
76309-/* Is the vma a continuation of the stack vma below it? */
76310-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
76311-{
76312- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
76313-}
76314-
76315-static inline int stack_guard_page_end(struct vm_area_struct *vma,
76316- unsigned long addr)
76317-{
76318- return (vma->vm_flags & VM_GROWSUP) &&
76319- (vma->vm_end == addr) &&
76320- !vma_growsup(vma->vm_next, addr);
76321-}
76322-
76323 extern pid_t
76324 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
76325
76326@@ -1180,6 +1158,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
76327 }
76328 #endif
76329
76330+#ifdef CONFIG_MMU
76331+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
76332+#else
76333+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76334+{
76335+ return __pgprot(0);
76336+}
76337+#endif
76338+
76339 int vma_wants_writenotify(struct vm_area_struct *vma);
76340
76341 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
76342@@ -1198,8 +1185,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
76343 {
76344 return 0;
76345 }
76346+
76347+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
76348+ unsigned long address)
76349+{
76350+ return 0;
76351+}
76352 #else
76353 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76354+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76355 #endif
76356
76357 #ifdef __PAGETABLE_PMD_FOLDED
76358@@ -1208,8 +1202,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
76359 {
76360 return 0;
76361 }
76362+
76363+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
76364+ unsigned long address)
76365+{
76366+ return 0;
76367+}
76368 #else
76369 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
76370+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
76371 #endif
76372
76373 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
76374@@ -1227,11 +1228,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
76375 NULL: pud_offset(pgd, address);
76376 }
76377
76378+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76379+{
76380+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
76381+ NULL: pud_offset(pgd, address);
76382+}
76383+
76384 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76385 {
76386 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
76387 NULL: pmd_offset(pud, address);
76388 }
76389+
76390+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76391+{
76392+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
76393+ NULL: pmd_offset(pud, address);
76394+}
76395 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
76396
76397 #if USE_SPLIT_PTLOCKS
76398@@ -1517,6 +1530,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76399 unsigned long len, unsigned long prot, unsigned long flags,
76400 unsigned long pgoff, unsigned long *populate);
76401 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
76402+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
76403
76404 #ifdef CONFIG_MMU
76405 extern int __mm_populate(unsigned long addr, unsigned long len,
76406@@ -1545,10 +1559,11 @@ struct vm_unmapped_area_info {
76407 unsigned long high_limit;
76408 unsigned long align_mask;
76409 unsigned long align_offset;
76410+ unsigned long threadstack_offset;
76411 };
76412
76413-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
76414-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76415+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
76416+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
76417
76418 /*
76419 * Search for an unmapped address range.
76420@@ -1560,7 +1575,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76421 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
76422 */
76423 static inline unsigned long
76424-vm_unmapped_area(struct vm_unmapped_area_info *info)
76425+vm_unmapped_area(const struct vm_unmapped_area_info *info)
76426 {
76427 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
76428 return unmapped_area(info);
76429@@ -1623,6 +1638,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
76430 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
76431 struct vm_area_struct **pprev);
76432
76433+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
76434+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
76435+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
76436+
76437 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
76438 NULL if none. Assume start_addr < end_addr. */
76439 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
76440@@ -1651,15 +1670,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
76441 return vma;
76442 }
76443
76444-#ifdef CONFIG_MMU
76445-pgprot_t vm_get_page_prot(unsigned long vm_flags);
76446-#else
76447-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
76448-{
76449- return __pgprot(0);
76450-}
76451-#endif
76452-
76453 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
76454 unsigned long change_prot_numa(struct vm_area_struct *vma,
76455 unsigned long start, unsigned long end);
76456@@ -1711,6 +1721,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
76457 static inline void vm_stat_account(struct mm_struct *mm,
76458 unsigned long flags, struct file *file, long pages)
76459 {
76460+
76461+#ifdef CONFIG_PAX_RANDMMAP
76462+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
76463+#endif
76464+
76465 mm->total_vm += pages;
76466 }
76467 #endif /* CONFIG_PROC_FS */
76468@@ -1791,7 +1806,7 @@ extern int unpoison_memory(unsigned long pfn);
76469 extern int sysctl_memory_failure_early_kill;
76470 extern int sysctl_memory_failure_recovery;
76471 extern void shake_page(struct page *p, int access);
76472-extern atomic_long_t num_poisoned_pages;
76473+extern atomic_long_unchecked_t num_poisoned_pages;
76474 extern int soft_offline_page(struct page *page, int flags);
76475
76476 extern void dump_page(struct page *page);
76477@@ -1828,5 +1843,11 @@ void __init setup_nr_node_ids(void);
76478 static inline void setup_nr_node_ids(void) {}
76479 #endif
76480
76481+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76482+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
76483+#else
76484+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
76485+#endif
76486+
76487 #endif /* __KERNEL__ */
76488 #endif /* _LINUX_MM_H */
76489diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
76490index 4a189ba..04101d6 100644
76491--- a/include/linux/mm_types.h
76492+++ b/include/linux/mm_types.h
76493@@ -289,6 +289,8 @@ struct vm_area_struct {
76494 #ifdef CONFIG_NUMA
76495 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
76496 #endif
76497+
76498+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
76499 };
76500
76501 struct core_thread {
76502@@ -438,6 +440,24 @@ struct mm_struct {
76503 int first_nid;
76504 #endif
76505 struct uprobes_state uprobes_state;
76506+
76507+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76508+ unsigned long pax_flags;
76509+#endif
76510+
76511+#ifdef CONFIG_PAX_DLRESOLVE
76512+ unsigned long call_dl_resolve;
76513+#endif
76514+
76515+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
76516+ unsigned long call_syscall;
76517+#endif
76518+
76519+#ifdef CONFIG_PAX_ASLR
76520+ unsigned long delta_mmap; /* randomized offset */
76521+ unsigned long delta_stack; /* randomized offset */
76522+#endif
76523+
76524 };
76525
76526 /* first nid will either be a valid NID or one of these values */
76527diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
76528index c5d5278..f0b68c8 100644
76529--- a/include/linux/mmiotrace.h
76530+++ b/include/linux/mmiotrace.h
76531@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
76532 /* Called from ioremap.c */
76533 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
76534 void __iomem *addr);
76535-extern void mmiotrace_iounmap(volatile void __iomem *addr);
76536+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
76537
76538 /* For anyone to insert markers. Remember trailing newline. */
76539 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
76540@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
76541 {
76542 }
76543
76544-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
76545+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
76546 {
76547 }
76548
76549diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
76550index 5c76737..61f518e 100644
76551--- a/include/linux/mmzone.h
76552+++ b/include/linux/mmzone.h
76553@@ -396,7 +396,7 @@ struct zone {
76554 unsigned long flags; /* zone flags, see below */
76555
76556 /* Zone statistics */
76557- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76558+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76559
76560 /*
76561 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
76562diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
76563index b508016..237cfe5 100644
76564--- a/include/linux/mod_devicetable.h
76565+++ b/include/linux/mod_devicetable.h
76566@@ -13,7 +13,7 @@
76567 typedef unsigned long kernel_ulong_t;
76568 #endif
76569
76570-#define PCI_ANY_ID (~0)
76571+#define PCI_ANY_ID ((__u16)~0)
76572
76573 struct pci_device_id {
76574 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
76575@@ -139,7 +139,7 @@ struct usb_device_id {
76576 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
76577 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
76578
76579-#define HID_ANY_ID (~0)
76580+#define HID_ANY_ID (~0U)
76581 #define HID_BUS_ANY 0xffff
76582 #define HID_GROUP_ANY 0x0000
76583
76584@@ -465,7 +465,7 @@ struct dmi_system_id {
76585 const char *ident;
76586 struct dmi_strmatch matches[4];
76587 void *driver_data;
76588-};
76589+} __do_const;
76590 /*
76591 * struct dmi_device_id appears during expansion of
76592 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
76593diff --git a/include/linux/module.h b/include/linux/module.h
76594index 46f1ea0..a34ca37 100644
76595--- a/include/linux/module.h
76596+++ b/include/linux/module.h
76597@@ -17,9 +17,11 @@
76598 #include <linux/moduleparam.h>
76599 #include <linux/tracepoint.h>
76600 #include <linux/export.h>
76601+#include <linux/fs.h>
76602
76603 #include <linux/percpu.h>
76604 #include <asm/module.h>
76605+#include <asm/pgtable.h>
76606
76607 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
76608 #define MODULE_SIG_STRING "~Module signature appended~\n"
76609@@ -54,12 +56,13 @@ struct module_attribute {
76610 int (*test)(struct module *);
76611 void (*free)(struct module *);
76612 };
76613+typedef struct module_attribute __no_const module_attribute_no_const;
76614
76615 struct module_version_attribute {
76616 struct module_attribute mattr;
76617 const char *module_name;
76618 const char *version;
76619-} __attribute__ ((__aligned__(sizeof(void *))));
76620+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
76621
76622 extern ssize_t __modver_version_show(struct module_attribute *,
76623 struct module_kobject *, char *);
76624@@ -232,7 +235,7 @@ struct module
76625
76626 /* Sysfs stuff. */
76627 struct module_kobject mkobj;
76628- struct module_attribute *modinfo_attrs;
76629+ module_attribute_no_const *modinfo_attrs;
76630 const char *version;
76631 const char *srcversion;
76632 struct kobject *holders_dir;
76633@@ -281,19 +284,16 @@ struct module
76634 int (*init)(void);
76635
76636 /* If this is non-NULL, vfree after init() returns */
76637- void *module_init;
76638+ void *module_init_rx, *module_init_rw;
76639
76640 /* Here is the actual code + data, vfree'd on unload. */
76641- void *module_core;
76642+ void *module_core_rx, *module_core_rw;
76643
76644 /* Here are the sizes of the init and core sections */
76645- unsigned int init_size, core_size;
76646+ unsigned int init_size_rw, core_size_rw;
76647
76648 /* The size of the executable code in each section. */
76649- unsigned int init_text_size, core_text_size;
76650-
76651- /* Size of RO sections of the module (text+rodata) */
76652- unsigned int init_ro_size, core_ro_size;
76653+ unsigned int init_size_rx, core_size_rx;
76654
76655 /* Arch-specific module values */
76656 struct mod_arch_specific arch;
76657@@ -349,6 +349,10 @@ struct module
76658 #ifdef CONFIG_EVENT_TRACING
76659 struct ftrace_event_call **trace_events;
76660 unsigned int num_trace_events;
76661+ struct file_operations trace_id;
76662+ struct file_operations trace_enable;
76663+ struct file_operations trace_format;
76664+ struct file_operations trace_filter;
76665 #endif
76666 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
76667 unsigned int num_ftrace_callsites;
76668@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
76669 bool is_module_percpu_address(unsigned long addr);
76670 bool is_module_text_address(unsigned long addr);
76671
76672+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
76673+{
76674+
76675+#ifdef CONFIG_PAX_KERNEXEC
76676+ if (ktla_ktva(addr) >= (unsigned long)start &&
76677+ ktla_ktva(addr) < (unsigned long)start + size)
76678+ return 1;
76679+#endif
76680+
76681+ return ((void *)addr >= start && (void *)addr < start + size);
76682+}
76683+
76684+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
76685+{
76686+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
76687+}
76688+
76689+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
76690+{
76691+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
76692+}
76693+
76694+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
76695+{
76696+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
76697+}
76698+
76699+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
76700+{
76701+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
76702+}
76703+
76704 static inline int within_module_core(unsigned long addr, const struct module *mod)
76705 {
76706- return (unsigned long)mod->module_core <= addr &&
76707- addr < (unsigned long)mod->module_core + mod->core_size;
76708+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
76709 }
76710
76711 static inline int within_module_init(unsigned long addr, const struct module *mod)
76712 {
76713- return (unsigned long)mod->module_init <= addr &&
76714- addr < (unsigned long)mod->module_init + mod->init_size;
76715+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
76716 }
76717
76718 /* Search for module by name: must hold module_mutex. */
76719diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
76720index 560ca53..ef621ef 100644
76721--- a/include/linux/moduleloader.h
76722+++ b/include/linux/moduleloader.h
76723@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
76724 sections. Returns NULL on failure. */
76725 void *module_alloc(unsigned long size);
76726
76727+#ifdef CONFIG_PAX_KERNEXEC
76728+void *module_alloc_exec(unsigned long size);
76729+#else
76730+#define module_alloc_exec(x) module_alloc(x)
76731+#endif
76732+
76733 /* Free memory returned from module_alloc. */
76734 void module_free(struct module *mod, void *module_region);
76735
76736+#ifdef CONFIG_PAX_KERNEXEC
76737+void module_free_exec(struct module *mod, void *module_region);
76738+#else
76739+#define module_free_exec(x, y) module_free((x), (y))
76740+#endif
76741+
76742 /*
76743 * Apply the given relocation to the (simplified) ELF. Return -error
76744 * or 0.
76745@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
76746 unsigned int relsec,
76747 struct module *me)
76748 {
76749+#ifdef CONFIG_MODULES
76750 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76751+#endif
76752 return -ENOEXEC;
76753 }
76754 #endif
76755@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
76756 unsigned int relsec,
76757 struct module *me)
76758 {
76759+#ifdef CONFIG_MODULES
76760 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76761+#endif
76762 return -ENOEXEC;
76763 }
76764 #endif
76765diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
76766index 137b419..fe663ec 100644
76767--- a/include/linux/moduleparam.h
76768+++ b/include/linux/moduleparam.h
76769@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
76770 * @len is usually just sizeof(string).
76771 */
76772 #define module_param_string(name, string, len, perm) \
76773- static const struct kparam_string __param_string_##name \
76774+ static const struct kparam_string __param_string_##name __used \
76775 = { len, string }; \
76776 __module_param_call(MODULE_PARAM_PREFIX, name, \
76777 &param_ops_string, \
76778@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
76779 */
76780 #define module_param_array_named(name, array, type, nump, perm) \
76781 param_check_##type(name, &(array)[0]); \
76782- static const struct kparam_array __param_arr_##name \
76783+ static const struct kparam_array __param_arr_##name __used \
76784 = { .max = ARRAY_SIZE(array), .num = nump, \
76785 .ops = &param_ops_##type, \
76786 .elemsize = sizeof(array[0]), .elem = array }; \
76787diff --git a/include/linux/namei.h b/include/linux/namei.h
76788index 5a5ff57..5ae5070 100644
76789--- a/include/linux/namei.h
76790+++ b/include/linux/namei.h
76791@@ -19,7 +19,7 @@ struct nameidata {
76792 unsigned seq;
76793 int last_type;
76794 unsigned depth;
76795- char *saved_names[MAX_NESTED_LINKS + 1];
76796+ const char *saved_names[MAX_NESTED_LINKS + 1];
76797 };
76798
76799 /*
76800@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
76801
76802 extern void nd_jump_link(struct nameidata *nd, struct path *path);
76803
76804-static inline void nd_set_link(struct nameidata *nd, char *path)
76805+static inline void nd_set_link(struct nameidata *nd, const char *path)
76806 {
76807 nd->saved_names[nd->depth] = path;
76808 }
76809
76810-static inline char *nd_get_link(struct nameidata *nd)
76811+static inline const char *nd_get_link(const struct nameidata *nd)
76812 {
76813 return nd->saved_names[nd->depth];
76814 }
76815diff --git a/include/linux/net.h b/include/linux/net.h
76816index 99c9f0c..e1cf296 100644
76817--- a/include/linux/net.h
76818+++ b/include/linux/net.h
76819@@ -183,7 +183,7 @@ struct net_proto_family {
76820 int (*create)(struct net *net, struct socket *sock,
76821 int protocol, int kern);
76822 struct module *owner;
76823-};
76824+} __do_const;
76825
76826 struct iovec;
76827 struct kvec;
76828diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
76829index 96e4c21..9cc8278 100644
76830--- a/include/linux/netdevice.h
76831+++ b/include/linux/netdevice.h
76832@@ -1026,6 +1026,7 @@ struct net_device_ops {
76833 int (*ndo_change_carrier)(struct net_device *dev,
76834 bool new_carrier);
76835 };
76836+typedef struct net_device_ops __no_const net_device_ops_no_const;
76837
76838 /*
76839 * The DEVICE structure.
76840@@ -1094,7 +1095,7 @@ struct net_device {
76841 int iflink;
76842
76843 struct net_device_stats stats;
76844- atomic_long_t rx_dropped; /* dropped packets by core network
76845+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
76846 * Do not use this in drivers.
76847 */
76848
76849diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
76850index 0060fde..481c6ae 100644
76851--- a/include/linux/netfilter.h
76852+++ b/include/linux/netfilter.h
76853@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
76854 #endif
76855 /* Use the module struct to lock set/get code in place */
76856 struct module *owner;
76857-};
76858+} __do_const;
76859
76860 /* Function to register/unregister hook points. */
76861 int nf_register_hook(struct nf_hook_ops *reg);
76862diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
76863index d80e275..c3510b8 100644
76864--- a/include/linux/netfilter/ipset/ip_set.h
76865+++ b/include/linux/netfilter/ipset/ip_set.h
76866@@ -124,7 +124,7 @@ struct ip_set_type_variant {
76867 /* Return true if "b" set is the same as "a"
76868 * according to the create set parameters */
76869 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
76870-};
76871+} __do_const;
76872
76873 /* The core set type structure */
76874 struct ip_set_type {
76875diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
76876index cadb740..d7c37c0 100644
76877--- a/include/linux/netfilter/nfnetlink.h
76878+++ b/include/linux/netfilter/nfnetlink.h
76879@@ -16,7 +16,7 @@ struct nfnl_callback {
76880 const struct nlattr * const cda[]);
76881 const struct nla_policy *policy; /* netlink attribute policy */
76882 const u_int16_t attr_count; /* number of nlattr's */
76883-};
76884+} __do_const;
76885
76886 struct nfnetlink_subsystem {
76887 const char *name;
76888diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
76889new file mode 100644
76890index 0000000..33f4af8
76891--- /dev/null
76892+++ b/include/linux/netfilter/xt_gradm.h
76893@@ -0,0 +1,9 @@
76894+#ifndef _LINUX_NETFILTER_XT_GRADM_H
76895+#define _LINUX_NETFILTER_XT_GRADM_H 1
76896+
76897+struct xt_gradm_mtinfo {
76898+ __u16 flags;
76899+ __u16 invflags;
76900+};
76901+
76902+#endif
76903diff --git a/include/linux/nls.h b/include/linux/nls.h
76904index 5dc635f..35f5e11 100644
76905--- a/include/linux/nls.h
76906+++ b/include/linux/nls.h
76907@@ -31,7 +31,7 @@ struct nls_table {
76908 const unsigned char *charset2upper;
76909 struct module *owner;
76910 struct nls_table *next;
76911-};
76912+} __do_const;
76913
76914 /* this value hold the maximum octet of charset */
76915 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
76916diff --git a/include/linux/notifier.h b/include/linux/notifier.h
76917index d14a4c3..a078786 100644
76918--- a/include/linux/notifier.h
76919+++ b/include/linux/notifier.h
76920@@ -54,7 +54,8 @@ struct notifier_block {
76921 notifier_fn_t notifier_call;
76922 struct notifier_block __rcu *next;
76923 int priority;
76924-};
76925+} __do_const;
76926+typedef struct notifier_block __no_const notifier_block_no_const;
76927
76928 struct atomic_notifier_head {
76929 spinlock_t lock;
76930diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
76931index a4c5624..79d6d88 100644
76932--- a/include/linux/oprofile.h
76933+++ b/include/linux/oprofile.h
76934@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
76935 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
76936 char const * name, ulong * val);
76937
76938-/** Create a file for read-only access to an atomic_t. */
76939+/** Create a file for read-only access to an atomic_unchecked_t. */
76940 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
76941- char const * name, atomic_t * val);
76942+ char const * name, atomic_unchecked_t * val);
76943
76944 /** create a directory */
76945 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
76946diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
76947index 8db71dc..a76bf2c 100644
76948--- a/include/linux/pci_hotplug.h
76949+++ b/include/linux/pci_hotplug.h
76950@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
76951 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
76952 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
76953 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
76954-};
76955+} __do_const;
76956+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
76957
76958 /**
76959 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
76960diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
76961index c5b6dbf..b124155 100644
76962--- a/include/linux/perf_event.h
76963+++ b/include/linux/perf_event.h
76964@@ -318,8 +318,8 @@ struct perf_event {
76965
76966 enum perf_event_active_state state;
76967 unsigned int attach_state;
76968- local64_t count;
76969- atomic64_t child_count;
76970+ local64_t count; /* PaX: fix it one day */
76971+ atomic64_unchecked_t child_count;
76972
76973 /*
76974 * These are the total time in nanoseconds that the event
76975@@ -370,8 +370,8 @@ struct perf_event {
76976 * These accumulate total time (in nanoseconds) that children
76977 * events have been enabled and running, respectively.
76978 */
76979- atomic64_t child_total_time_enabled;
76980- atomic64_t child_total_time_running;
76981+ atomic64_unchecked_t child_total_time_enabled;
76982+ atomic64_unchecked_t child_total_time_running;
76983
76984 /*
76985 * Protect attach/detach and child_list:
76986@@ -692,7 +692,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
76987 entry->ip[entry->nr++] = ip;
76988 }
76989
76990-extern int sysctl_perf_event_paranoid;
76991+extern int sysctl_perf_event_legitimately_concerned;
76992 extern int sysctl_perf_event_mlock;
76993 extern int sysctl_perf_event_sample_rate;
76994
76995@@ -700,19 +700,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
76996 void __user *buffer, size_t *lenp,
76997 loff_t *ppos);
76998
76999+static inline bool perf_paranoid_any(void)
77000+{
77001+ return sysctl_perf_event_legitimately_concerned > 2;
77002+}
77003+
77004 static inline bool perf_paranoid_tracepoint_raw(void)
77005 {
77006- return sysctl_perf_event_paranoid > -1;
77007+ return sysctl_perf_event_legitimately_concerned > -1;
77008 }
77009
77010 static inline bool perf_paranoid_cpu(void)
77011 {
77012- return sysctl_perf_event_paranoid > 0;
77013+ return sysctl_perf_event_legitimately_concerned > 0;
77014 }
77015
77016 static inline bool perf_paranoid_kernel(void)
77017 {
77018- return sysctl_perf_event_paranoid > 1;
77019+ return sysctl_perf_event_legitimately_concerned > 1;
77020 }
77021
77022 extern void perf_event_init(void);
77023@@ -806,7 +811,7 @@ static inline void perf_restore_debug_store(void) { }
77024 */
77025 #define perf_cpu_notifier(fn) \
77026 do { \
77027- static struct notifier_block fn##_nb __cpuinitdata = \
77028+ static struct notifier_block fn##_nb = \
77029 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
77030 unsigned long cpu = smp_processor_id(); \
77031 unsigned long flags; \
77032@@ -826,7 +831,7 @@ struct perf_pmu_events_attr {
77033 struct device_attribute attr;
77034 u64 id;
77035 const char *event_str;
77036-};
77037+} __do_const;
77038
77039 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
77040 static struct perf_pmu_events_attr _var = { \
77041diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
77042index b8809fe..ae4ccd0 100644
77043--- a/include/linux/pipe_fs_i.h
77044+++ b/include/linux/pipe_fs_i.h
77045@@ -47,10 +47,10 @@ struct pipe_inode_info {
77046 struct mutex mutex;
77047 wait_queue_head_t wait;
77048 unsigned int nrbufs, curbuf, buffers;
77049- unsigned int readers;
77050- unsigned int writers;
77051- unsigned int files;
77052- unsigned int waiting_writers;
77053+ atomic_t readers;
77054+ atomic_t writers;
77055+ atomic_t files;
77056+ atomic_t waiting_writers;
77057 unsigned int r_counter;
77058 unsigned int w_counter;
77059 struct page *tmp_page;
77060diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
77061index 5f28cae..3d23723 100644
77062--- a/include/linux/platform_data/usb-ehci-s5p.h
77063+++ b/include/linux/platform_data/usb-ehci-s5p.h
77064@@ -14,7 +14,7 @@
77065 struct s5p_ehci_platdata {
77066 int (*phy_init)(struct platform_device *pdev, int type);
77067 int (*phy_exit)(struct platform_device *pdev, int type);
77068-};
77069+} __no_const;
77070
77071 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
77072
77073diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
77074index c256c59..8ea94c7 100644
77075--- a/include/linux/platform_data/usb-ohci-exynos.h
77076+++ b/include/linux/platform_data/usb-ohci-exynos.h
77077@@ -14,7 +14,7 @@
77078 struct exynos4_ohci_platdata {
77079 int (*phy_init)(struct platform_device *pdev, int type);
77080 int (*phy_exit)(struct platform_device *pdev, int type);
77081-};
77082+} __no_const;
77083
77084 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
77085
77086diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
77087index 7c1d252..c5c773e 100644
77088--- a/include/linux/pm_domain.h
77089+++ b/include/linux/pm_domain.h
77090@@ -48,7 +48,7 @@ struct gpd_dev_ops {
77091
77092 struct gpd_cpu_data {
77093 unsigned int saved_exit_latency;
77094- struct cpuidle_state *idle_state;
77095+ cpuidle_state_no_const *idle_state;
77096 };
77097
77098 struct generic_pm_domain {
77099diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
77100index 7d7e09e..8671ef8 100644
77101--- a/include/linux/pm_runtime.h
77102+++ b/include/linux/pm_runtime.h
77103@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
77104
77105 static inline void pm_runtime_mark_last_busy(struct device *dev)
77106 {
77107- ACCESS_ONCE(dev->power.last_busy) = jiffies;
77108+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
77109 }
77110
77111 #else /* !CONFIG_PM_RUNTIME */
77112diff --git a/include/linux/pnp.h b/include/linux/pnp.h
77113index 195aafc..49a7bc2 100644
77114--- a/include/linux/pnp.h
77115+++ b/include/linux/pnp.h
77116@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
77117 struct pnp_fixup {
77118 char id[7];
77119 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
77120-};
77121+} __do_const;
77122
77123 /* config parameters */
77124 #define PNP_CONFIG_NORMAL 0x0001
77125diff --git a/include/linux/poison.h b/include/linux/poison.h
77126index 2110a81..13a11bb 100644
77127--- a/include/linux/poison.h
77128+++ b/include/linux/poison.h
77129@@ -19,8 +19,8 @@
77130 * under normal circumstances, used to verify that nobody uses
77131 * non-initialized list entries.
77132 */
77133-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
77134-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
77135+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
77136+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
77137
77138 /********** include/linux/timer.h **********/
77139 /*
77140diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
77141index c0f44c2..1572583 100644
77142--- a/include/linux/power/smartreflex.h
77143+++ b/include/linux/power/smartreflex.h
77144@@ -238,7 +238,7 @@ struct omap_sr_class_data {
77145 int (*notify)(struct omap_sr *sr, u32 status);
77146 u8 notify_flags;
77147 u8 class_type;
77148-};
77149+} __do_const;
77150
77151 /**
77152 * struct omap_sr_nvalue_table - Smartreflex n-target value info
77153diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
77154index 4ea1d37..80f4b33 100644
77155--- a/include/linux/ppp-comp.h
77156+++ b/include/linux/ppp-comp.h
77157@@ -84,7 +84,7 @@ struct compressor {
77158 struct module *owner;
77159 /* Extra skb space needed by the compressor algorithm */
77160 unsigned int comp_extra;
77161-};
77162+} __do_const;
77163
77164 /*
77165 * The return value from decompress routine is the length of the
77166diff --git a/include/linux/preempt.h b/include/linux/preempt.h
77167index f5d4723..a6ea2fa 100644
77168--- a/include/linux/preempt.h
77169+++ b/include/linux/preempt.h
77170@@ -18,8 +18,13 @@
77171 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77172 #endif
77173
77174+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
77175+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
77176+
77177 #define inc_preempt_count() add_preempt_count(1)
77178+#define raw_inc_preempt_count() raw_add_preempt_count(1)
77179 #define dec_preempt_count() sub_preempt_count(1)
77180+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
77181
77182 #define preempt_count() (current_thread_info()->preempt_count)
77183
77184@@ -64,6 +69,12 @@ do { \
77185 barrier(); \
77186 } while (0)
77187
77188+#define raw_preempt_disable() \
77189+do { \
77190+ raw_inc_preempt_count(); \
77191+ barrier(); \
77192+} while (0)
77193+
77194 #define sched_preempt_enable_no_resched() \
77195 do { \
77196 barrier(); \
77197@@ -72,6 +83,12 @@ do { \
77198
77199 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
77200
77201+#define raw_preempt_enable_no_resched() \
77202+do { \
77203+ barrier(); \
77204+ raw_dec_preempt_count(); \
77205+} while (0)
77206+
77207 #define preempt_enable() \
77208 do { \
77209 preempt_enable_no_resched(); \
77210@@ -116,8 +133,10 @@ do { \
77211 * region.
77212 */
77213 #define preempt_disable() barrier()
77214+#define raw_preempt_disable() barrier()
77215 #define sched_preempt_enable_no_resched() barrier()
77216 #define preempt_enable_no_resched() barrier()
77217+#define raw_preempt_enable_no_resched() barrier()
77218 #define preempt_enable() barrier()
77219
77220 #define preempt_disable_notrace() barrier()
77221diff --git a/include/linux/printk.h b/include/linux/printk.h
77222index 22c7052..ad3fa0a 100644
77223--- a/include/linux/printk.h
77224+++ b/include/linux/printk.h
77225@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
77226 void early_printk(const char *s, ...) { }
77227 #endif
77228
77229+extern int kptr_restrict;
77230+
77231 #ifdef CONFIG_PRINTK
77232 asmlinkage __printf(5, 0)
77233 int vprintk_emit(int facility, int level,
77234@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
77235
77236 extern int printk_delay_msec;
77237 extern int dmesg_restrict;
77238-extern int kptr_restrict;
77239
77240 extern void wake_up_klogd(void);
77241
77242diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
77243index 608e60a..c26f864 100644
77244--- a/include/linux/proc_fs.h
77245+++ b/include/linux/proc_fs.h
77246@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
77247 return proc_create_data(name, mode, parent, proc_fops, NULL);
77248 }
77249
77250+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
77251+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
77252+{
77253+#ifdef CONFIG_GRKERNSEC_PROC_USER
77254+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
77255+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77256+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
77257+#else
77258+ return proc_create_data(name, mode, parent, proc_fops, NULL);
77259+#endif
77260+}
77261+
77262+
77263 extern void proc_set_size(struct proc_dir_entry *, loff_t);
77264 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
77265 extern void *PDE_DATA(const struct inode *);
77266diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
77267index 34a1e10..03a6d03 100644
77268--- a/include/linux/proc_ns.h
77269+++ b/include/linux/proc_ns.h
77270@@ -14,7 +14,7 @@ struct proc_ns_operations {
77271 void (*put)(void *ns);
77272 int (*install)(struct nsproxy *nsproxy, void *ns);
77273 unsigned int (*inum)(void *ns);
77274-};
77275+} __do_const;
77276
77277 struct proc_ns {
77278 void *ns;
77279diff --git a/include/linux/random.h b/include/linux/random.h
77280index 3b9377d..61b506a 100644
77281--- a/include/linux/random.h
77282+++ b/include/linux/random.h
77283@@ -32,6 +32,11 @@ void prandom_seed(u32 seed);
77284 u32 prandom_u32_state(struct rnd_state *);
77285 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
77286
77287+static inline unsigned long pax_get_random_long(void)
77288+{
77289+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
77290+}
77291+
77292 /*
77293 * Handle minimum values for seeds
77294 */
77295diff --git a/include/linux/rculist.h b/include/linux/rculist.h
77296index f4b1001..8ddb2b6 100644
77297--- a/include/linux/rculist.h
77298+++ b/include/linux/rculist.h
77299@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
77300 struct list_head *prev, struct list_head *next);
77301 #endif
77302
77303+extern void __pax_list_add_rcu(struct list_head *new,
77304+ struct list_head *prev, struct list_head *next);
77305+
77306 /**
77307 * list_add_rcu - add a new entry to rcu-protected list
77308 * @new: new entry to be added
77309@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
77310 __list_add_rcu(new, head, head->next);
77311 }
77312
77313+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
77314+{
77315+ __pax_list_add_rcu(new, head, head->next);
77316+}
77317+
77318 /**
77319 * list_add_tail_rcu - add a new entry to rcu-protected list
77320 * @new: new entry to be added
77321@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
77322 __list_add_rcu(new, head->prev, head);
77323 }
77324
77325+static inline void pax_list_add_tail_rcu(struct list_head *new,
77326+ struct list_head *head)
77327+{
77328+ __pax_list_add_rcu(new, head->prev, head);
77329+}
77330+
77331 /**
77332 * list_del_rcu - deletes entry from list without re-initialization
77333 * @entry: the element to delete from the list.
77334@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
77335 entry->prev = LIST_POISON2;
77336 }
77337
77338+extern void pax_list_del_rcu(struct list_head *entry);
77339+
77340 /**
77341 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
77342 * @n: the element to delete from the hash list.
77343diff --git a/include/linux/reboot.h b/include/linux/reboot.h
77344index 23b3630..e1bc12b 100644
77345--- a/include/linux/reboot.h
77346+++ b/include/linux/reboot.h
77347@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
77348 * Architecture-specific implementations of sys_reboot commands.
77349 */
77350
77351-extern void machine_restart(char *cmd);
77352-extern void machine_halt(void);
77353-extern void machine_power_off(void);
77354+extern void machine_restart(char *cmd) __noreturn;
77355+extern void machine_halt(void) __noreturn;
77356+extern void machine_power_off(void) __noreturn;
77357
77358 extern void machine_shutdown(void);
77359 struct pt_regs;
77360@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
77361 */
77362
77363 extern void kernel_restart_prepare(char *cmd);
77364-extern void kernel_restart(char *cmd);
77365-extern void kernel_halt(void);
77366-extern void kernel_power_off(void);
77367+extern void kernel_restart(char *cmd) __noreturn;
77368+extern void kernel_halt(void) __noreturn;
77369+extern void kernel_power_off(void) __noreturn;
77370
77371 extern int C_A_D; /* for sysctl */
77372 void ctrl_alt_del(void);
77373@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
77374 * Emergency restart, callable from an interrupt handler.
77375 */
77376
77377-extern void emergency_restart(void);
77378+extern void emergency_restart(void) __noreturn;
77379 #include <asm/emergency-restart.h>
77380
77381 #endif /* _LINUX_REBOOT_H */
77382diff --git a/include/linux/regset.h b/include/linux/regset.h
77383index 8e0c9fe..ac4d221 100644
77384--- a/include/linux/regset.h
77385+++ b/include/linux/regset.h
77386@@ -161,7 +161,8 @@ struct user_regset {
77387 unsigned int align;
77388 unsigned int bias;
77389 unsigned int core_note_type;
77390-};
77391+} __do_const;
77392+typedef struct user_regset __no_const user_regset_no_const;
77393
77394 /**
77395 * struct user_regset_view - available regsets
77396diff --git a/include/linux/relay.h b/include/linux/relay.h
77397index d7c8359..818daf5 100644
77398--- a/include/linux/relay.h
77399+++ b/include/linux/relay.h
77400@@ -157,7 +157,7 @@ struct rchan_callbacks
77401 * The callback should return 0 if successful, negative if not.
77402 */
77403 int (*remove_buf_file)(struct dentry *dentry);
77404-};
77405+} __no_const;
77406
77407 /*
77408 * CONFIG_RELAY kernel API, kernel/relay.c
77409diff --git a/include/linux/rio.h b/include/linux/rio.h
77410index 18e0993..8ab5b21 100644
77411--- a/include/linux/rio.h
77412+++ b/include/linux/rio.h
77413@@ -345,7 +345,7 @@ struct rio_ops {
77414 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
77415 u64 rstart, u32 size, u32 flags);
77416 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
77417-};
77418+} __no_const;
77419
77420 #define RIO_RESOURCE_MEM 0x00000100
77421 #define RIO_RESOURCE_DOORBELL 0x00000200
77422diff --git a/include/linux/rmap.h b/include/linux/rmap.h
77423index 6dacb93..6174423 100644
77424--- a/include/linux/rmap.h
77425+++ b/include/linux/rmap.h
77426@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
77427 void anon_vma_init(void); /* create anon_vma_cachep */
77428 int anon_vma_prepare(struct vm_area_struct *);
77429 void unlink_anon_vmas(struct vm_area_struct *);
77430-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
77431-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
77432+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
77433+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
77434
77435 static inline void anon_vma_merge(struct vm_area_struct *vma,
77436 struct vm_area_struct *next)
77437diff --git a/include/linux/sched.h b/include/linux/sched.h
77438index 178a8d9..918ea01 100644
77439--- a/include/linux/sched.h
77440+++ b/include/linux/sched.h
77441@@ -62,6 +62,7 @@ struct bio_list;
77442 struct fs_struct;
77443 struct perf_event_context;
77444 struct blk_plug;
77445+struct linux_binprm;
77446
77447 /*
77448 * List of flags we want to share for kernel threads,
77449@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
77450 extern int in_sched_functions(unsigned long addr);
77451
77452 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
77453-extern signed long schedule_timeout(signed long timeout);
77454+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
77455 extern signed long schedule_timeout_interruptible(signed long timeout);
77456 extern signed long schedule_timeout_killable(signed long timeout);
77457 extern signed long schedule_timeout_uninterruptible(signed long timeout);
77458@@ -314,6 +315,18 @@ struct nsproxy;
77459 struct user_namespace;
77460
77461 #ifdef CONFIG_MMU
77462+
77463+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
77464+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
77465+#else
77466+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
77467+{
77468+ return 0;
77469+}
77470+#endif
77471+
77472+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
77473+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
77474 extern void arch_pick_mmap_layout(struct mm_struct *mm);
77475 extern unsigned long
77476 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
77477@@ -591,6 +604,17 @@ struct signal_struct {
77478 #ifdef CONFIG_TASKSTATS
77479 struct taskstats *stats;
77480 #endif
77481+
77482+#ifdef CONFIG_GRKERNSEC
77483+ u32 curr_ip;
77484+ u32 saved_ip;
77485+ u32 gr_saddr;
77486+ u32 gr_daddr;
77487+ u16 gr_sport;
77488+ u16 gr_dport;
77489+ u8 used_accept:1;
77490+#endif
77491+
77492 #ifdef CONFIG_AUDIT
77493 unsigned audit_tty;
77494 unsigned audit_tty_log_passwd;
77495@@ -671,6 +695,14 @@ struct user_struct {
77496 struct key *session_keyring; /* UID's default session keyring */
77497 #endif
77498
77499+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77500+ unsigned char kernel_banned;
77501+#endif
77502+#ifdef CONFIG_GRKERNSEC_BRUTE
77503+ unsigned char suid_banned;
77504+ unsigned long suid_ban_expires;
77505+#endif
77506+
77507 /* Hash table maintenance information */
77508 struct hlist_node uidhash_node;
77509 kuid_t uid;
77510@@ -1158,8 +1190,8 @@ struct task_struct {
77511 struct list_head thread_group;
77512
77513 struct completion *vfork_done; /* for vfork() */
77514- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
77515- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77516+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
77517+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77518
77519 cputime_t utime, stime, utimescaled, stimescaled;
77520 cputime_t gtime;
77521@@ -1184,11 +1216,6 @@ struct task_struct {
77522 struct task_cputime cputime_expires;
77523 struct list_head cpu_timers[3];
77524
77525-/* process credentials */
77526- const struct cred __rcu *real_cred; /* objective and real subjective task
77527- * credentials (COW) */
77528- const struct cred __rcu *cred; /* effective (overridable) subjective task
77529- * credentials (COW) */
77530 char comm[TASK_COMM_LEN]; /* executable name excluding path
77531 - access with [gs]et_task_comm (which lock
77532 it with task_lock())
77533@@ -1205,6 +1232,10 @@ struct task_struct {
77534 #endif
77535 /* CPU-specific state of this task */
77536 struct thread_struct thread;
77537+/* thread_info moved to task_struct */
77538+#ifdef CONFIG_X86
77539+ struct thread_info tinfo;
77540+#endif
77541 /* filesystem information */
77542 struct fs_struct *fs;
77543 /* open file information */
77544@@ -1278,6 +1309,10 @@ struct task_struct {
77545 gfp_t lockdep_reclaim_gfp;
77546 #endif
77547
77548+/* process credentials */
77549+ const struct cred __rcu *real_cred; /* objective and real subjective task
77550+ * credentials (COW) */
77551+
77552 /* journalling filesystem info */
77553 void *journal_info;
77554
77555@@ -1316,6 +1351,10 @@ struct task_struct {
77556 /* cg_list protected by css_set_lock and tsk->alloc_lock */
77557 struct list_head cg_list;
77558 #endif
77559+
77560+ const struct cred __rcu *cred; /* effective (overridable) subjective task
77561+ * credentials (COW) */
77562+
77563 #ifdef CONFIG_FUTEX
77564 struct robust_list_head __user *robust_list;
77565 #ifdef CONFIG_COMPAT
77566@@ -1416,8 +1455,76 @@ struct task_struct {
77567 unsigned int sequential_io;
77568 unsigned int sequential_io_avg;
77569 #endif
77570+
77571+#ifdef CONFIG_GRKERNSEC
77572+ /* grsecurity */
77573+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77574+ u64 exec_id;
77575+#endif
77576+#ifdef CONFIG_GRKERNSEC_SETXID
77577+ const struct cred *delayed_cred;
77578+#endif
77579+ struct dentry *gr_chroot_dentry;
77580+ struct acl_subject_label *acl;
77581+ struct acl_role_label *role;
77582+ struct file *exec_file;
77583+ unsigned long brute_expires;
77584+ u16 acl_role_id;
77585+ /* is this the task that authenticated to the special role */
77586+ u8 acl_sp_role;
77587+ u8 is_writable;
77588+ u8 brute;
77589+ u8 gr_is_chrooted;
77590+#endif
77591+
77592 };
77593
77594+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
77595+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
77596+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
77597+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
77598+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
77599+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
77600+
77601+#ifdef CONFIG_PAX_SOFTMODE
77602+extern int pax_softmode;
77603+#endif
77604+
77605+extern int pax_check_flags(unsigned long *);
77606+
77607+/* if tsk != current then task_lock must be held on it */
77608+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
77609+static inline unsigned long pax_get_flags(struct task_struct *tsk)
77610+{
77611+ if (likely(tsk->mm))
77612+ return tsk->mm->pax_flags;
77613+ else
77614+ return 0UL;
77615+}
77616+
77617+/* if tsk != current then task_lock must be held on it */
77618+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
77619+{
77620+ if (likely(tsk->mm)) {
77621+ tsk->mm->pax_flags = flags;
77622+ return 0;
77623+ }
77624+ return -EINVAL;
77625+}
77626+#endif
77627+
77628+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77629+extern void pax_set_initial_flags(struct linux_binprm *bprm);
77630+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
77631+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
77632+#endif
77633+
77634+struct path;
77635+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
77636+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
77637+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
77638+extern void pax_report_refcount_overflow(struct pt_regs *regs);
77639+
77640 /* Future-safe accessor for struct task_struct's cpus_allowed. */
77641 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
77642
77643@@ -1476,7 +1583,7 @@ struct pid_namespace;
77644 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
77645 struct pid_namespace *ns);
77646
77647-static inline pid_t task_pid_nr(struct task_struct *tsk)
77648+static inline pid_t task_pid_nr(const struct task_struct *tsk)
77649 {
77650 return tsk->pid;
77651 }
77652@@ -1919,7 +2026,9 @@ void yield(void);
77653 extern struct exec_domain default_exec_domain;
77654
77655 union thread_union {
77656+#ifndef CONFIG_X86
77657 struct thread_info thread_info;
77658+#endif
77659 unsigned long stack[THREAD_SIZE/sizeof(long)];
77660 };
77661
77662@@ -1952,6 +2061,7 @@ extern struct pid_namespace init_pid_ns;
77663 */
77664
77665 extern struct task_struct *find_task_by_vpid(pid_t nr);
77666+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
77667 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
77668 struct pid_namespace *ns);
77669
77670@@ -2118,7 +2228,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
77671 extern void exit_itimers(struct signal_struct *);
77672 extern void flush_itimer_signals(void);
77673
77674-extern void do_group_exit(int);
77675+extern __noreturn void do_group_exit(int);
77676
77677 extern int allow_signal(int);
77678 extern int disallow_signal(int);
77679@@ -2309,9 +2419,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
77680
77681 #endif
77682
77683-static inline int object_is_on_stack(void *obj)
77684+static inline int object_starts_on_stack(void *obj)
77685 {
77686- void *stack = task_stack_page(current);
77687+ const void *stack = task_stack_page(current);
77688
77689 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
77690 }
77691diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
77692index bf8086b..962b035 100644
77693--- a/include/linux/sched/sysctl.h
77694+++ b/include/linux/sched/sysctl.h
77695@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
77696 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
77697
77698 extern int sysctl_max_map_count;
77699+extern unsigned long sysctl_heap_stack_gap;
77700
77701 extern unsigned int sysctl_sched_latency;
77702 extern unsigned int sysctl_sched_min_granularity;
77703diff --git a/include/linux/security.h b/include/linux/security.h
77704index 4686491..2bd210e 100644
77705--- a/include/linux/security.h
77706+++ b/include/linux/security.h
77707@@ -26,6 +26,7 @@
77708 #include <linux/capability.h>
77709 #include <linux/slab.h>
77710 #include <linux/err.h>
77711+#include <linux/grsecurity.h>
77712
77713 struct linux_binprm;
77714 struct cred;
77715diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
77716index 2da29ac..aac448ec 100644
77717--- a/include/linux/seq_file.h
77718+++ b/include/linux/seq_file.h
77719@@ -26,6 +26,9 @@ struct seq_file {
77720 struct mutex lock;
77721 const struct seq_operations *op;
77722 int poll_event;
77723+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77724+ u64 exec_id;
77725+#endif
77726 #ifdef CONFIG_USER_NS
77727 struct user_namespace *user_ns;
77728 #endif
77729@@ -38,6 +41,7 @@ struct seq_operations {
77730 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
77731 int (*show) (struct seq_file *m, void *v);
77732 };
77733+typedef struct seq_operations __no_const seq_operations_no_const;
77734
77735 #define SEQ_SKIP 1
77736
77737diff --git a/include/linux/shm.h b/include/linux/shm.h
77738index 429c199..4d42e38 100644
77739--- a/include/linux/shm.h
77740+++ b/include/linux/shm.h
77741@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
77742
77743 /* The task created the shm object. NULL if the task is dead. */
77744 struct task_struct *shm_creator;
77745+#ifdef CONFIG_GRKERNSEC
77746+ time_t shm_createtime;
77747+ pid_t shm_lapid;
77748+#endif
77749 };
77750
77751 /* shm_mode upper byte flags */
77752diff --git a/include/linux/signal.h b/include/linux/signal.h
77753index d897484..323ba98 100644
77754--- a/include/linux/signal.h
77755+++ b/include/linux/signal.h
77756@@ -433,6 +433,7 @@ void signals_init(void);
77757
77758 int restore_altstack(const stack_t __user *);
77759 int __save_altstack(stack_t __user *, unsigned long);
77760+void __save_altstack_ex(stack_t __user *, unsigned long);
77761
77762 #ifdef CONFIG_PROC_FS
77763 struct seq_file;
77764diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
77765index dec1748..112c1f9 100644
77766--- a/include/linux/skbuff.h
77767+++ b/include/linux/skbuff.h
77768@@ -640,7 +640,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
77769 extern struct sk_buff *__alloc_skb(unsigned int size,
77770 gfp_t priority, int flags, int node);
77771 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
77772-static inline struct sk_buff *alloc_skb(unsigned int size,
77773+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
77774 gfp_t priority)
77775 {
77776 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
77777@@ -756,7 +756,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
77778 */
77779 static inline int skb_queue_empty(const struct sk_buff_head *list)
77780 {
77781- return list->next == (struct sk_buff *)list;
77782+ return list->next == (const struct sk_buff *)list;
77783 }
77784
77785 /**
77786@@ -769,7 +769,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
77787 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77788 const struct sk_buff *skb)
77789 {
77790- return skb->next == (struct sk_buff *)list;
77791+ return skb->next == (const struct sk_buff *)list;
77792 }
77793
77794 /**
77795@@ -782,7 +782,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77796 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
77797 const struct sk_buff *skb)
77798 {
77799- return skb->prev == (struct sk_buff *)list;
77800+ return skb->prev == (const struct sk_buff *)list;
77801 }
77802
77803 /**
77804@@ -1848,7 +1848,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
77805 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
77806 */
77807 #ifndef NET_SKB_PAD
77808-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
77809+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
77810 #endif
77811
77812 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
77813@@ -2443,7 +2443,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
77814 int noblock, int *err);
77815 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
77816 struct poll_table_struct *wait);
77817-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
77818+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
77819 int offset, struct iovec *to,
77820 int size);
77821 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
77822@@ -2733,6 +2733,9 @@ static inline void nf_reset(struct sk_buff *skb)
77823 nf_bridge_put(skb->nf_bridge);
77824 skb->nf_bridge = NULL;
77825 #endif
77826+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
77827+ skb->nf_trace = 0;
77828+#endif
77829 }
77830
77831 static inline void nf_reset_trace(struct sk_buff *skb)
77832diff --git a/include/linux/slab.h b/include/linux/slab.h
77833index 0c62175..f016ac1 100644
77834--- a/include/linux/slab.h
77835+++ b/include/linux/slab.h
77836@@ -12,15 +12,29 @@
77837 #include <linux/gfp.h>
77838 #include <linux/types.h>
77839 #include <linux/workqueue.h>
77840-
77841+#include <linux/err.h>
77842
77843 /*
77844 * Flags to pass to kmem_cache_create().
77845 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
77846 */
77847 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
77848+
77849+#ifdef CONFIG_PAX_USERCOPY_SLABS
77850+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
77851+#else
77852+#define SLAB_USERCOPY 0x00000000UL
77853+#endif
77854+
77855 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
77856 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
77857+
77858+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77859+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
77860+#else
77861+#define SLAB_NO_SANITIZE 0x00000000UL
77862+#endif
77863+
77864 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
77865 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
77866 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
77867@@ -89,10 +103,13 @@
77868 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
77869 * Both make kfree a no-op.
77870 */
77871-#define ZERO_SIZE_PTR ((void *)16)
77872+#define ZERO_SIZE_PTR \
77873+({ \
77874+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
77875+ (void *)(-MAX_ERRNO-1L); \
77876+})
77877
77878-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
77879- (unsigned long)ZERO_SIZE_PTR)
77880+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
77881
77882
77883 struct mem_cgroup;
77884@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
77885 void kfree(const void *);
77886 void kzfree(const void *);
77887 size_t ksize(const void *);
77888+const char *check_heap_object(const void *ptr, unsigned long n);
77889+bool is_usercopy_object(const void *ptr);
77890
77891 /*
77892 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
77893@@ -164,7 +183,7 @@ struct kmem_cache {
77894 unsigned int align; /* Alignment as calculated */
77895 unsigned long flags; /* Active flags on the slab */
77896 const char *name; /* Slab name for sysfs */
77897- int refcount; /* Use counter */
77898+ atomic_t refcount; /* Use counter */
77899 void (*ctor)(void *); /* Called on object slot creation */
77900 struct list_head list; /* List of all slab caches on the system */
77901 };
77902@@ -226,6 +245,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
77903 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77904 #endif
77905
77906+#ifdef CONFIG_PAX_USERCOPY_SLABS
77907+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
77908+#endif
77909+
77910 /*
77911 * Figure out which kmalloc slab an allocation of a certain size
77912 * belongs to.
77913@@ -234,7 +257,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77914 * 2 = 120 .. 192 bytes
77915 * n = 2^(n-1) .. 2^n -1
77916 */
77917-static __always_inline int kmalloc_index(size_t size)
77918+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
77919 {
77920 if (!size)
77921 return 0;
77922@@ -406,6 +429,7 @@ void print_slabinfo_header(struct seq_file *m);
77923 * for general use, and so are not documented here. For a full list of
77924 * potential flags, always refer to linux/gfp.h.
77925 */
77926+
77927 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
77928 {
77929 if (size != 0 && n > SIZE_MAX / size)
77930@@ -465,7 +489,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
77931 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
77932 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
77933 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
77934-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
77935+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
77936 #define kmalloc_track_caller(size, flags) \
77937 __kmalloc_track_caller(size, flags, _RET_IP_)
77938 #else
77939@@ -485,7 +509,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
77940 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
77941 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
77942 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
77943-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
77944+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
77945 #define kmalloc_node_track_caller(size, flags, node) \
77946 __kmalloc_node_track_caller(size, flags, node, \
77947 _RET_IP_)
77948diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
77949index cd40158..4e2f7af 100644
77950--- a/include/linux/slab_def.h
77951+++ b/include/linux/slab_def.h
77952@@ -50,7 +50,7 @@ struct kmem_cache {
77953 /* 4) cache creation/removal */
77954 const char *name;
77955 struct list_head list;
77956- int refcount;
77957+ atomic_t refcount;
77958 int object_size;
77959 int align;
77960
77961@@ -66,10 +66,14 @@ struct kmem_cache {
77962 unsigned long node_allocs;
77963 unsigned long node_frees;
77964 unsigned long node_overflow;
77965- atomic_t allochit;
77966- atomic_t allocmiss;
77967- atomic_t freehit;
77968- atomic_t freemiss;
77969+ atomic_unchecked_t allochit;
77970+ atomic_unchecked_t allocmiss;
77971+ atomic_unchecked_t freehit;
77972+ atomic_unchecked_t freemiss;
77973+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77974+ atomic_unchecked_t sanitized;
77975+ atomic_unchecked_t not_sanitized;
77976+#endif
77977
77978 /*
77979 * If debugging is enabled, then the allocator can add additional
77980@@ -103,7 +107,7 @@ struct kmem_cache {
77981 };
77982
77983 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
77984-void *__kmalloc(size_t size, gfp_t flags);
77985+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
77986
77987 #ifdef CONFIG_TRACING
77988 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
77989@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
77990 cachep = kmalloc_dma_caches[i];
77991 else
77992 #endif
77993+
77994+#ifdef CONFIG_PAX_USERCOPY_SLABS
77995+ if (flags & GFP_USERCOPY)
77996+ cachep = kmalloc_usercopy_caches[i];
77997+ else
77998+#endif
77999+
78000 cachep = kmalloc_caches[i];
78001
78002 ret = kmem_cache_alloc_trace(cachep, flags, size);
78003@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
78004 }
78005
78006 #ifdef CONFIG_NUMA
78007-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
78008+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
78009 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
78010
78011 #ifdef CONFIG_TRACING
78012@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
78013 cachep = kmalloc_dma_caches[i];
78014 else
78015 #endif
78016+
78017+#ifdef CONFIG_PAX_USERCOPY_SLABS
78018+ if (flags & GFP_USERCOPY)
78019+ cachep = kmalloc_usercopy_caches[i];
78020+ else
78021+#endif
78022+
78023 cachep = kmalloc_caches[i];
78024
78025 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
78026diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
78027index f28e14a..7831211 100644
78028--- a/include/linux/slob_def.h
78029+++ b/include/linux/slob_def.h
78030@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
78031 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
78032 }
78033
78034-void *__kmalloc_node(size_t size, gfp_t flags, int node);
78035+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
78036
78037 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
78038 {
78039@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
78040 return __kmalloc_node(size, flags, NUMA_NO_NODE);
78041 }
78042
78043-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
78044+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
78045 {
78046 return kmalloc(size, flags);
78047 }
78048diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
78049index 027276f..092bfe8 100644
78050--- a/include/linux/slub_def.h
78051+++ b/include/linux/slub_def.h
78052@@ -80,7 +80,7 @@ struct kmem_cache {
78053 struct kmem_cache_order_objects max;
78054 struct kmem_cache_order_objects min;
78055 gfp_t allocflags; /* gfp flags to use on each alloc */
78056- int refcount; /* Refcount for slab cache destroy */
78057+ atomic_t refcount; /* Refcount for slab cache destroy */
78058 void (*ctor)(void *);
78059 int inuse; /* Offset to metadata */
78060 int align; /* Alignment */
78061@@ -105,7 +105,7 @@ struct kmem_cache {
78062 };
78063
78064 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
78065-void *__kmalloc(size_t size, gfp_t flags);
78066+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
78067
78068 static __always_inline void *
78069 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
78070@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
78071 }
78072 #endif
78073
78074-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
78075+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
78076 {
78077 unsigned int order = get_order(size);
78078 return kmalloc_order_trace(size, flags, order);
78079@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
78080 }
78081
78082 #ifdef CONFIG_NUMA
78083-void *__kmalloc_node(size_t size, gfp_t flags, int node);
78084+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
78085 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
78086
78087 #ifdef CONFIG_TRACING
78088diff --git a/include/linux/smp.h b/include/linux/smp.h
78089index c848876..11e8a84 100644
78090--- a/include/linux/smp.h
78091+++ b/include/linux/smp.h
78092@@ -221,7 +221,9 @@ static inline void kick_all_cpus_sync(void) { }
78093 #endif
78094
78095 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
78096+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
78097 #define put_cpu() preempt_enable()
78098+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
78099
78100 /*
78101 * Callback to arch code if there's nosmp or maxcpus=0 on the
78102diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
78103index 54f91d3..be2c379 100644
78104--- a/include/linux/sock_diag.h
78105+++ b/include/linux/sock_diag.h
78106@@ -11,7 +11,7 @@ struct sock;
78107 struct sock_diag_handler {
78108 __u8 family;
78109 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
78110-};
78111+} __do_const;
78112
78113 int sock_diag_register(const struct sock_diag_handler *h);
78114 void sock_diag_unregister(const struct sock_diag_handler *h);
78115diff --git a/include/linux/sonet.h b/include/linux/sonet.h
78116index 680f9a3..f13aeb0 100644
78117--- a/include/linux/sonet.h
78118+++ b/include/linux/sonet.h
78119@@ -7,7 +7,7 @@
78120 #include <uapi/linux/sonet.h>
78121
78122 struct k_sonet_stats {
78123-#define __HANDLE_ITEM(i) atomic_t i
78124+#define __HANDLE_ITEM(i) atomic_unchecked_t i
78125 __SONET_ITEMS
78126 #undef __HANDLE_ITEM
78127 };
78128diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
78129index 07d8e53..dc934c9 100644
78130--- a/include/linux/sunrpc/addr.h
78131+++ b/include/linux/sunrpc/addr.h
78132@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
78133 {
78134 switch (sap->sa_family) {
78135 case AF_INET:
78136- return ntohs(((struct sockaddr_in *)sap)->sin_port);
78137+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
78138 case AF_INET6:
78139- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
78140+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
78141 }
78142 return 0;
78143 }
78144@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
78145 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
78146 const struct sockaddr *src)
78147 {
78148- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
78149+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
78150 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
78151
78152 dsin->sin_family = ssin->sin_family;
78153@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
78154 if (sa->sa_family != AF_INET6)
78155 return 0;
78156
78157- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
78158+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
78159 }
78160
78161 #endif /* _LINUX_SUNRPC_ADDR_H */
78162diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
78163index bfe11be..12bc8c4 100644
78164--- a/include/linux/sunrpc/clnt.h
78165+++ b/include/linux/sunrpc/clnt.h
78166@@ -96,7 +96,7 @@ struct rpc_procinfo {
78167 unsigned int p_timer; /* Which RTT timer to use */
78168 u32 p_statidx; /* Which procedure to account */
78169 const char * p_name; /* name of procedure */
78170-};
78171+} __do_const;
78172
78173 #ifdef __KERNEL__
78174
78175diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
78176index 1f0216b..6a4fa50 100644
78177--- a/include/linux/sunrpc/svc.h
78178+++ b/include/linux/sunrpc/svc.h
78179@@ -411,7 +411,7 @@ struct svc_procedure {
78180 unsigned int pc_count; /* call count */
78181 unsigned int pc_cachetype; /* cache info (NFS) */
78182 unsigned int pc_xdrressize; /* maximum size of XDR reply */
78183-};
78184+} __do_const;
78185
78186 /*
78187 * Function prototypes.
78188diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
78189index 0b8e3e6..33e0a01 100644
78190--- a/include/linux/sunrpc/svc_rdma.h
78191+++ b/include/linux/sunrpc/svc_rdma.h
78192@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
78193 extern unsigned int svcrdma_max_requests;
78194 extern unsigned int svcrdma_max_req_size;
78195
78196-extern atomic_t rdma_stat_recv;
78197-extern atomic_t rdma_stat_read;
78198-extern atomic_t rdma_stat_write;
78199-extern atomic_t rdma_stat_sq_starve;
78200-extern atomic_t rdma_stat_rq_starve;
78201-extern atomic_t rdma_stat_rq_poll;
78202-extern atomic_t rdma_stat_rq_prod;
78203-extern atomic_t rdma_stat_sq_poll;
78204-extern atomic_t rdma_stat_sq_prod;
78205+extern atomic_unchecked_t rdma_stat_recv;
78206+extern atomic_unchecked_t rdma_stat_read;
78207+extern atomic_unchecked_t rdma_stat_write;
78208+extern atomic_unchecked_t rdma_stat_sq_starve;
78209+extern atomic_unchecked_t rdma_stat_rq_starve;
78210+extern atomic_unchecked_t rdma_stat_rq_poll;
78211+extern atomic_unchecked_t rdma_stat_rq_prod;
78212+extern atomic_unchecked_t rdma_stat_sq_poll;
78213+extern atomic_unchecked_t rdma_stat_sq_prod;
78214
78215 #define RPCRDMA_VERSION 1
78216
78217diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
78218index ff374ab..7fd2ecb 100644
78219--- a/include/linux/sunrpc/svcauth.h
78220+++ b/include/linux/sunrpc/svcauth.h
78221@@ -109,7 +109,7 @@ struct auth_ops {
78222 int (*release)(struct svc_rqst *rq);
78223 void (*domain_release)(struct auth_domain *);
78224 int (*set_client)(struct svc_rqst *rq);
78225-};
78226+} __do_const;
78227
78228 #define SVC_GARBAGE 1
78229 #define SVC_SYSERR 2
78230diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
78231index a5ffd32..0935dea 100644
78232--- a/include/linux/swiotlb.h
78233+++ b/include/linux/swiotlb.h
78234@@ -60,7 +60,8 @@ extern void
78235
78236 extern void
78237 swiotlb_free_coherent(struct device *hwdev, size_t size,
78238- void *vaddr, dma_addr_t dma_handle);
78239+ void *vaddr, dma_addr_t dma_handle,
78240+ struct dma_attrs *attrs);
78241
78242 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
78243 unsigned long offset, size_t size,
78244diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
78245index 84662ec..d8f8adb 100644
78246--- a/include/linux/syscalls.h
78247+++ b/include/linux/syscalls.h
78248@@ -97,8 +97,12 @@ struct sigaltstack;
78249 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
78250
78251 #define __SC_DECL(t, a) t a
78252-#define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
78253-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
78254+#define __TYPE_IS_SL(t) (__same_type((t)0, 0L))
78255+#define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
78256+#define __TYPE_IS_SLL(t) (__same_type((t)0, 0LL))
78257+#define __TYPE_IS_ULL(t) (__same_type((t)0, 0ULL))
78258+#define __TYPE_IS_LL(t) (__TYPE_IS_SLL(t) || __TYPE_IS_ULL(t))
78259+#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), __builtin_choose_expr(__TYPE_IS_ULL(t), 0ULL, 0LL), __builtin_choose_expr(__TYPE_IS_UL(t), 0UL, 0L))) a
78260 #define __SC_CAST(t, a) (t) a
78261 #define __SC_ARGS(t, a) a
78262 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
78263@@ -362,11 +366,11 @@ asmlinkage long sys_sync(void);
78264 asmlinkage long sys_fsync(unsigned int fd);
78265 asmlinkage long sys_fdatasync(unsigned int fd);
78266 asmlinkage long sys_bdflush(int func, long data);
78267-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
78268- char __user *type, unsigned long flags,
78269+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
78270+ const char __user *type, unsigned long flags,
78271 void __user *data);
78272-asmlinkage long sys_umount(char __user *name, int flags);
78273-asmlinkage long sys_oldumount(char __user *name);
78274+asmlinkage long sys_umount(const char __user *name, int flags);
78275+asmlinkage long sys_oldumount(const char __user *name);
78276 asmlinkage long sys_truncate(const char __user *path, long length);
78277 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
78278 asmlinkage long sys_stat(const char __user *filename,
78279@@ -578,7 +582,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
78280 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
78281 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
78282 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
78283- struct sockaddr __user *, int);
78284+ struct sockaddr __user *, int) __intentional_overflow(0);
78285 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
78286 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
78287 unsigned int vlen, unsigned flags);
78288diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
78289index 27b3b0b..e093dd9 100644
78290--- a/include/linux/syscore_ops.h
78291+++ b/include/linux/syscore_ops.h
78292@@ -16,7 +16,7 @@ struct syscore_ops {
78293 int (*suspend)(void);
78294 void (*resume)(void);
78295 void (*shutdown)(void);
78296-};
78297+} __do_const;
78298
78299 extern void register_syscore_ops(struct syscore_ops *ops);
78300 extern void unregister_syscore_ops(struct syscore_ops *ops);
78301diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
78302index 14a8ff2..af52bad 100644
78303--- a/include/linux/sysctl.h
78304+++ b/include/linux/sysctl.h
78305@@ -34,13 +34,13 @@ struct ctl_table_root;
78306 struct ctl_table_header;
78307 struct ctl_dir;
78308
78309-typedef struct ctl_table ctl_table;
78310-
78311 typedef int proc_handler (struct ctl_table *ctl, int write,
78312 void __user *buffer, size_t *lenp, loff_t *ppos);
78313
78314 extern int proc_dostring(struct ctl_table *, int,
78315 void __user *, size_t *, loff_t *);
78316+extern int proc_dostring_modpriv(struct ctl_table *, int,
78317+ void __user *, size_t *, loff_t *);
78318 extern int proc_dointvec(struct ctl_table *, int,
78319 void __user *, size_t *, loff_t *);
78320 extern int proc_dointvec_minmax(struct ctl_table *, int,
78321@@ -115,7 +115,9 @@ struct ctl_table
78322 struct ctl_table_poll *poll;
78323 void *extra1;
78324 void *extra2;
78325-};
78326+} __do_const;
78327+typedef struct ctl_table __no_const ctl_table_no_const;
78328+typedef struct ctl_table ctl_table;
78329
78330 struct ctl_node {
78331 struct rb_node node;
78332diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
78333index e2cee22..3ddb921 100644
78334--- a/include/linux/sysfs.h
78335+++ b/include/linux/sysfs.h
78336@@ -31,7 +31,8 @@ struct attribute {
78337 struct lock_class_key *key;
78338 struct lock_class_key skey;
78339 #endif
78340-};
78341+} __do_const;
78342+typedef struct attribute __no_const attribute_no_const;
78343
78344 /**
78345 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
78346@@ -59,8 +60,8 @@ struct attribute_group {
78347 umode_t (*is_visible)(struct kobject *,
78348 struct attribute *, int);
78349 struct attribute **attrs;
78350-};
78351-
78352+} __do_const;
78353+typedef struct attribute_group __no_const attribute_group_no_const;
78354
78355
78356 /**
78357@@ -107,7 +108,8 @@ struct bin_attribute {
78358 char *, loff_t, size_t);
78359 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
78360 struct vm_area_struct *vma);
78361-};
78362+} __do_const;
78363+typedef struct bin_attribute __no_const bin_attribute_no_const;
78364
78365 /**
78366 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
78367diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
78368index 7faf933..9b85a0c 100644
78369--- a/include/linux/sysrq.h
78370+++ b/include/linux/sysrq.h
78371@@ -16,6 +16,7 @@
78372
78373 #include <linux/errno.h>
78374 #include <linux/types.h>
78375+#include <linux/compiler.h>
78376
78377 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
78378 #define SYSRQ_DEFAULT_ENABLE 1
78379@@ -36,7 +37,7 @@ struct sysrq_key_op {
78380 char *help_msg;
78381 char *action_msg;
78382 int enable_mask;
78383-};
78384+} __do_const;
78385
78386 #ifdef CONFIG_MAGIC_SYSRQ
78387
78388diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
78389index e7e0473..7989295 100644
78390--- a/include/linux/thread_info.h
78391+++ b/include/linux/thread_info.h
78392@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
78393 #error "no set_restore_sigmask() provided and default one won't work"
78394 #endif
78395
78396+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
78397+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
78398+{
78399+#ifndef CONFIG_PAX_USERCOPY_DEBUG
78400+ if (!__builtin_constant_p(n))
78401+#endif
78402+ __check_object_size(ptr, n, to_user);
78403+}
78404+
78405 #endif /* __KERNEL__ */
78406
78407 #endif /* _LINUX_THREAD_INFO_H */
78408diff --git a/include/linux/tty.h b/include/linux/tty.h
78409index 8780bd2..d1ae08b 100644
78410--- a/include/linux/tty.h
78411+++ b/include/linux/tty.h
78412@@ -194,7 +194,7 @@ struct tty_port {
78413 const struct tty_port_operations *ops; /* Port operations */
78414 spinlock_t lock; /* Lock protecting tty field */
78415 int blocked_open; /* Waiting to open */
78416- int count; /* Usage count */
78417+ atomic_t count; /* Usage count */
78418 wait_queue_head_t open_wait; /* Open waiters */
78419 wait_queue_head_t close_wait; /* Close waiters */
78420 wait_queue_head_t delta_msr_wait; /* Modem status change */
78421@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
78422 struct tty_struct *tty, struct file *filp);
78423 static inline int tty_port_users(struct tty_port *port)
78424 {
78425- return port->count + port->blocked_open;
78426+ return atomic_read(&port->count) + port->blocked_open;
78427 }
78428
78429 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
78430diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
78431index 756a609..b302dd6 100644
78432--- a/include/linux/tty_driver.h
78433+++ b/include/linux/tty_driver.h
78434@@ -285,7 +285,7 @@ struct tty_operations {
78435 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
78436 #endif
78437 const struct file_operations *proc_fops;
78438-};
78439+} __do_const;
78440
78441 struct tty_driver {
78442 int magic; /* magic number for this structure */
78443diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
78444index 58390c7..95e214c 100644
78445--- a/include/linux/tty_ldisc.h
78446+++ b/include/linux/tty_ldisc.h
78447@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
78448
78449 struct module *owner;
78450
78451- int refcount;
78452+ atomic_t refcount;
78453 };
78454
78455 struct tty_ldisc {
78456diff --git a/include/linux/types.h b/include/linux/types.h
78457index 4d118ba..c3ee9bf 100644
78458--- a/include/linux/types.h
78459+++ b/include/linux/types.h
78460@@ -176,10 +176,26 @@ typedef struct {
78461 int counter;
78462 } atomic_t;
78463
78464+#ifdef CONFIG_PAX_REFCOUNT
78465+typedef struct {
78466+ int counter;
78467+} atomic_unchecked_t;
78468+#else
78469+typedef atomic_t atomic_unchecked_t;
78470+#endif
78471+
78472 #ifdef CONFIG_64BIT
78473 typedef struct {
78474 long counter;
78475 } atomic64_t;
78476+
78477+#ifdef CONFIG_PAX_REFCOUNT
78478+typedef struct {
78479+ long counter;
78480+} atomic64_unchecked_t;
78481+#else
78482+typedef atomic64_t atomic64_unchecked_t;
78483+#endif
78484 #endif
78485
78486 struct list_head {
78487diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
78488index 5ca0951..ab496a5 100644
78489--- a/include/linux/uaccess.h
78490+++ b/include/linux/uaccess.h
78491@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
78492 long ret; \
78493 mm_segment_t old_fs = get_fs(); \
78494 \
78495- set_fs(KERNEL_DS); \
78496 pagefault_disable(); \
78497- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
78498- pagefault_enable(); \
78499+ set_fs(KERNEL_DS); \
78500+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
78501 set_fs(old_fs); \
78502+ pagefault_enable(); \
78503 ret; \
78504 })
78505
78506diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
78507index 8e522cbc..aa8572d 100644
78508--- a/include/linux/uidgid.h
78509+++ b/include/linux/uidgid.h
78510@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
78511
78512 #endif /* CONFIG_USER_NS */
78513
78514+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
78515+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
78516+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
78517+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
78518+
78519 #endif /* _LINUX_UIDGID_H */
78520diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
78521index 99c1b4d..562e6f3 100644
78522--- a/include/linux/unaligned/access_ok.h
78523+++ b/include/linux/unaligned/access_ok.h
78524@@ -4,34 +4,34 @@
78525 #include <linux/kernel.h>
78526 #include <asm/byteorder.h>
78527
78528-static inline u16 get_unaligned_le16(const void *p)
78529+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
78530 {
78531- return le16_to_cpup((__le16 *)p);
78532+ return le16_to_cpup((const __le16 *)p);
78533 }
78534
78535-static inline u32 get_unaligned_le32(const void *p)
78536+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
78537 {
78538- return le32_to_cpup((__le32 *)p);
78539+ return le32_to_cpup((const __le32 *)p);
78540 }
78541
78542-static inline u64 get_unaligned_le64(const void *p)
78543+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
78544 {
78545- return le64_to_cpup((__le64 *)p);
78546+ return le64_to_cpup((const __le64 *)p);
78547 }
78548
78549-static inline u16 get_unaligned_be16(const void *p)
78550+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
78551 {
78552- return be16_to_cpup((__be16 *)p);
78553+ return be16_to_cpup((const __be16 *)p);
78554 }
78555
78556-static inline u32 get_unaligned_be32(const void *p)
78557+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
78558 {
78559- return be32_to_cpup((__be32 *)p);
78560+ return be32_to_cpup((const __be32 *)p);
78561 }
78562
78563-static inline u64 get_unaligned_be64(const void *p)
78564+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
78565 {
78566- return be64_to_cpup((__be64 *)p);
78567+ return be64_to_cpup((const __be64 *)p);
78568 }
78569
78570 static inline void put_unaligned_le16(u16 val, void *p)
78571diff --git a/include/linux/usb.h b/include/linux/usb.h
78572index a0bee5a..5533a52 100644
78573--- a/include/linux/usb.h
78574+++ b/include/linux/usb.h
78575@@ -552,7 +552,7 @@ struct usb_device {
78576 int maxchild;
78577
78578 u32 quirks;
78579- atomic_t urbnum;
78580+ atomic_unchecked_t urbnum;
78581
78582 unsigned long active_duration;
78583
78584@@ -1607,7 +1607,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
78585
78586 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
78587 __u8 request, __u8 requesttype, __u16 value, __u16 index,
78588- void *data, __u16 size, int timeout);
78589+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
78590 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
78591 void *data, int len, int *actual_length, int timeout);
78592 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
78593diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
78594index e452ba6..78f8e80 100644
78595--- a/include/linux/usb/renesas_usbhs.h
78596+++ b/include/linux/usb/renesas_usbhs.h
78597@@ -39,7 +39,7 @@ enum {
78598 */
78599 struct renesas_usbhs_driver_callback {
78600 int (*notify_hotplug)(struct platform_device *pdev);
78601-};
78602+} __no_const;
78603
78604 /*
78605 * callback functions for platform
78606diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
78607index 6f8fbcf..8259001 100644
78608--- a/include/linux/vermagic.h
78609+++ b/include/linux/vermagic.h
78610@@ -25,9 +25,35 @@
78611 #define MODULE_ARCH_VERMAGIC ""
78612 #endif
78613
78614+#ifdef CONFIG_PAX_REFCOUNT
78615+#define MODULE_PAX_REFCOUNT "REFCOUNT "
78616+#else
78617+#define MODULE_PAX_REFCOUNT ""
78618+#endif
78619+
78620+#ifdef CONSTIFY_PLUGIN
78621+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
78622+#else
78623+#define MODULE_CONSTIFY_PLUGIN ""
78624+#endif
78625+
78626+#ifdef STACKLEAK_PLUGIN
78627+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
78628+#else
78629+#define MODULE_STACKLEAK_PLUGIN ""
78630+#endif
78631+
78632+#ifdef CONFIG_GRKERNSEC
78633+#define MODULE_GRSEC "GRSEC "
78634+#else
78635+#define MODULE_GRSEC ""
78636+#endif
78637+
78638 #define VERMAGIC_STRING \
78639 UTS_RELEASE " " \
78640 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
78641 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
78642- MODULE_ARCH_VERMAGIC
78643+ MODULE_ARCH_VERMAGIC \
78644+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
78645+ MODULE_GRSEC
78646
78647diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
78648index 7d5773a..541c01c 100644
78649--- a/include/linux/vmalloc.h
78650+++ b/include/linux/vmalloc.h
78651@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
78652 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
78653 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
78654 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
78655+
78656+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78657+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
78658+#endif
78659+
78660 /* bits [20..32] reserved for arch specific ioremap internals */
78661
78662 /*
78663@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
78664 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
78665 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
78666 unsigned long start, unsigned long end, gfp_t gfp_mask,
78667- pgprot_t prot, int node, const void *caller);
78668+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
78669 extern void vfree(const void *addr);
78670
78671 extern void *vmap(struct page **pages, unsigned int count,
78672@@ -137,8 +142,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
78673 extern void free_vm_area(struct vm_struct *area);
78674
78675 /* for /dev/kmem */
78676-extern long vread(char *buf, char *addr, unsigned long count);
78677-extern long vwrite(char *buf, char *addr, unsigned long count);
78678+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
78679+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
78680
78681 /*
78682 * Internals. Dont't use..
78683diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
78684index c586679..f06b389 100644
78685--- a/include/linux/vmstat.h
78686+++ b/include/linux/vmstat.h
78687@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
78688 /*
78689 * Zone based page accounting with per cpu differentials.
78690 */
78691-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78692+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78693
78694 static inline void zone_page_state_add(long x, struct zone *zone,
78695 enum zone_stat_item item)
78696 {
78697- atomic_long_add(x, &zone->vm_stat[item]);
78698- atomic_long_add(x, &vm_stat[item]);
78699+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
78700+ atomic_long_add_unchecked(x, &vm_stat[item]);
78701 }
78702
78703 static inline unsigned long global_page_state(enum zone_stat_item item)
78704 {
78705- long x = atomic_long_read(&vm_stat[item]);
78706+ long x = atomic_long_read_unchecked(&vm_stat[item]);
78707 #ifdef CONFIG_SMP
78708 if (x < 0)
78709 x = 0;
78710@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
78711 static inline unsigned long zone_page_state(struct zone *zone,
78712 enum zone_stat_item item)
78713 {
78714- long x = atomic_long_read(&zone->vm_stat[item]);
78715+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78716 #ifdef CONFIG_SMP
78717 if (x < 0)
78718 x = 0;
78719@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
78720 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
78721 enum zone_stat_item item)
78722 {
78723- long x = atomic_long_read(&zone->vm_stat[item]);
78724+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78725
78726 #ifdef CONFIG_SMP
78727 int cpu;
78728@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
78729
78730 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
78731 {
78732- atomic_long_inc(&zone->vm_stat[item]);
78733- atomic_long_inc(&vm_stat[item]);
78734+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
78735+ atomic_long_inc_unchecked(&vm_stat[item]);
78736 }
78737
78738 static inline void __inc_zone_page_state(struct page *page,
78739@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
78740
78741 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
78742 {
78743- atomic_long_dec(&zone->vm_stat[item]);
78744- atomic_long_dec(&vm_stat[item]);
78745+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
78746+ atomic_long_dec_unchecked(&vm_stat[item]);
78747 }
78748
78749 static inline void __dec_zone_page_state(struct page *page,
78750diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
78751index 623488f..44b5742 100644
78752--- a/include/linux/workqueue.h
78753+++ b/include/linux/workqueue.h
78754@@ -410,11 +410,11 @@ __alloc_workqueue_key(const char *fmt, unsigned int flags, int max_active,
78755 alloc_workqueue(fmt, WQ_UNBOUND | __WQ_ORDERED | (flags), 1, ##args)
78756
78757 #define create_workqueue(name) \
78758- alloc_workqueue((name), WQ_MEM_RECLAIM, 1)
78759+ alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, (name))
78760 #define create_freezable_workqueue(name) \
78761- alloc_workqueue((name), WQ_FREEZABLE | WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
78762+ alloc_workqueue("%s", WQ_FREEZABLE | WQ_UNBOUND | WQ_MEM_RECLAIM, 1, (name))
78763 #define create_singlethread_workqueue(name) \
78764- alloc_workqueue((name), WQ_UNBOUND | WQ_MEM_RECLAIM, 1)
78765+ alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, (name))
78766
78767 extern void destroy_workqueue(struct workqueue_struct *wq);
78768
78769diff --git a/include/linux/xattr.h b/include/linux/xattr.h
78770index fdbafc6..49dfe4f 100644
78771--- a/include/linux/xattr.h
78772+++ b/include/linux/xattr.h
78773@@ -28,7 +28,7 @@ struct xattr_handler {
78774 size_t size, int handler_flags);
78775 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
78776 size_t size, int flags, int handler_flags);
78777-};
78778+} __do_const;
78779
78780 struct xattr {
78781 char *name;
78782@@ -37,6 +37,9 @@ struct xattr {
78783 };
78784
78785 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
78786+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78787+ssize_t pax_getxattr(struct dentry *, void *, size_t);
78788+#endif
78789 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
78790 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
78791 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
78792diff --git a/include/linux/zlib.h b/include/linux/zlib.h
78793index 9c5a6b4..09c9438 100644
78794--- a/include/linux/zlib.h
78795+++ b/include/linux/zlib.h
78796@@ -31,6 +31,7 @@
78797 #define _ZLIB_H
78798
78799 #include <linux/zconf.h>
78800+#include <linux/compiler.h>
78801
78802 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
78803 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
78804@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
78805
78806 /* basic functions */
78807
78808-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
78809+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
78810 /*
78811 Returns the number of bytes that needs to be allocated for a per-
78812 stream workspace with the specified parameters. A pointer to this
78813diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
78814index 95d1c91..6798cca 100644
78815--- a/include/media/v4l2-dev.h
78816+++ b/include/media/v4l2-dev.h
78817@@ -76,7 +76,7 @@ struct v4l2_file_operations {
78818 int (*mmap) (struct file *, struct vm_area_struct *);
78819 int (*open) (struct file *);
78820 int (*release) (struct file *);
78821-};
78822+} __do_const;
78823
78824 /*
78825 * Newer version of video_device, handled by videodev2.c
78826diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
78827index c9b1593..a572459 100644
78828--- a/include/media/v4l2-device.h
78829+++ b/include/media/v4l2-device.h
78830@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
78831 this function returns 0. If the name ends with a digit (e.g. cx18),
78832 then the name will be set to cx18-0 since cx180 looks really odd. */
78833 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
78834- atomic_t *instance);
78835+ atomic_unchecked_t *instance);
78836
78837 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
78838 Since the parent disappears this ensures that v4l2_dev doesn't have an
78839diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
78840index adcbb20..62c2559 100644
78841--- a/include/net/9p/transport.h
78842+++ b/include/net/9p/transport.h
78843@@ -57,7 +57,7 @@ struct p9_trans_module {
78844 int (*cancel) (struct p9_client *, struct p9_req_t *req);
78845 int (*zc_request)(struct p9_client *, struct p9_req_t *,
78846 char *, char *, int , int, int, int);
78847-};
78848+} __do_const;
78849
78850 void v9fs_register_trans(struct p9_trans_module *m);
78851 void v9fs_unregister_trans(struct p9_trans_module *m);
78852diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
78853index fb94cf1..7c0c987 100644
78854--- a/include/net/bluetooth/l2cap.h
78855+++ b/include/net/bluetooth/l2cap.h
78856@@ -551,7 +551,7 @@ struct l2cap_ops {
78857 void (*defer) (struct l2cap_chan *chan);
78858 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
78859 unsigned long len, int nb);
78860-};
78861+} __do_const;
78862
78863 struct l2cap_conn {
78864 struct hci_conn *hcon;
78865diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
78866index f2ae33d..c457cf0 100644
78867--- a/include/net/caif/cfctrl.h
78868+++ b/include/net/caif/cfctrl.h
78869@@ -52,7 +52,7 @@ struct cfctrl_rsp {
78870 void (*radioset_rsp)(void);
78871 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
78872 struct cflayer *client_layer);
78873-};
78874+} __no_const;
78875
78876 /* Link Setup Parameters for CAIF-Links. */
78877 struct cfctrl_link_param {
78878@@ -101,8 +101,8 @@ struct cfctrl_request_info {
78879 struct cfctrl {
78880 struct cfsrvl serv;
78881 struct cfctrl_rsp res;
78882- atomic_t req_seq_no;
78883- atomic_t rsp_seq_no;
78884+ atomic_unchecked_t req_seq_no;
78885+ atomic_unchecked_t rsp_seq_no;
78886 struct list_head list;
78887 /* Protects from simultaneous access to first_req list */
78888 spinlock_t info_list_lock;
78889diff --git a/include/net/flow.h b/include/net/flow.h
78890index 628e11b..4c475df 100644
78891--- a/include/net/flow.h
78892+++ b/include/net/flow.h
78893@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
78894
78895 extern void flow_cache_flush(void);
78896 extern void flow_cache_flush_deferred(void);
78897-extern atomic_t flow_cache_genid;
78898+extern atomic_unchecked_t flow_cache_genid;
78899
78900 #endif
78901diff --git a/include/net/genetlink.h b/include/net/genetlink.h
78902index 93024a4..eeb6b6e 100644
78903--- a/include/net/genetlink.h
78904+++ b/include/net/genetlink.h
78905@@ -119,7 +119,7 @@ struct genl_ops {
78906 struct netlink_callback *cb);
78907 int (*done)(struct netlink_callback *cb);
78908 struct list_head ops_list;
78909-};
78910+} __do_const;
78911
78912 extern int genl_register_family(struct genl_family *family);
78913 extern int genl_register_family_with_ops(struct genl_family *family,
78914diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
78915index 734d9b5..48a9a4b 100644
78916--- a/include/net/gro_cells.h
78917+++ b/include/net/gro_cells.h
78918@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
78919 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
78920
78921 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
78922- atomic_long_inc(&dev->rx_dropped);
78923+ atomic_long_inc_unchecked(&dev->rx_dropped);
78924 kfree_skb(skb);
78925 return;
78926 }
78927diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
78928index de2c785..0588a6b 100644
78929--- a/include/net/inet_connection_sock.h
78930+++ b/include/net/inet_connection_sock.h
78931@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
78932 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
78933 int (*bind_conflict)(const struct sock *sk,
78934 const struct inet_bind_bucket *tb, bool relax);
78935-};
78936+} __do_const;
78937
78938 /** inet_connection_sock - INET connection oriented sock
78939 *
78940diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
78941index 53f464d..0bd0b49 100644
78942--- a/include/net/inetpeer.h
78943+++ b/include/net/inetpeer.h
78944@@ -47,8 +47,8 @@ struct inet_peer {
78945 */
78946 union {
78947 struct {
78948- atomic_t rid; /* Frag reception counter */
78949- atomic_t ip_id_count; /* IP ID for the next packet */
78950+ atomic_unchecked_t rid; /* Frag reception counter */
78951+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
78952 };
78953 struct rcu_head rcu;
78954 struct inet_peer *gc_next;
78955@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
78956 /* can be called with or without local BH being disabled */
78957 static inline int inet_getid(struct inet_peer *p, int more)
78958 {
78959- int old, new;
78960+ int id;
78961 more++;
78962 inet_peer_refcheck(p);
78963- do {
78964- old = atomic_read(&p->ip_id_count);
78965- new = old + more;
78966- if (!new)
78967- new = 1;
78968- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
78969- return new;
78970+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
78971+ if (!id)
78972+ id = atomic_inc_return_unchecked(&p->ip_id_count);
78973+ return id;
78974 }
78975
78976 #endif /* _NET_INETPEER_H */
78977diff --git a/include/net/ip.h b/include/net/ip.h
78978index a68f838..74518ab 100644
78979--- a/include/net/ip.h
78980+++ b/include/net/ip.h
78981@@ -202,7 +202,7 @@ extern struct local_ports {
78982 } sysctl_local_ports;
78983 extern void inet_get_local_port_range(int *low, int *high);
78984
78985-extern unsigned long *sysctl_local_reserved_ports;
78986+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
78987 static inline int inet_is_reserved_local_port(int port)
78988 {
78989 return test_bit(port, sysctl_local_reserved_ports);
78990diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
78991index e49db91..76a81de 100644
78992--- a/include/net/ip_fib.h
78993+++ b/include/net/ip_fib.h
78994@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
78995
78996 #define FIB_RES_SADDR(net, res) \
78997 ((FIB_RES_NH(res).nh_saddr_genid == \
78998- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
78999+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
79000 FIB_RES_NH(res).nh_saddr : \
79001 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
79002 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
79003diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
79004index 4c062cc..3562c31 100644
79005--- a/include/net/ip_vs.h
79006+++ b/include/net/ip_vs.h
79007@@ -612,7 +612,7 @@ struct ip_vs_conn {
79008 struct ip_vs_conn *control; /* Master control connection */
79009 atomic_t n_control; /* Number of controlled ones */
79010 struct ip_vs_dest *dest; /* real server */
79011- atomic_t in_pkts; /* incoming packet counter */
79012+ atomic_unchecked_t in_pkts; /* incoming packet counter */
79013
79014 /* packet transmitter for different forwarding methods. If it
79015 mangles the packet, it must return NF_DROP or better NF_STOLEN,
79016@@ -761,7 +761,7 @@ struct ip_vs_dest {
79017 __be16 port; /* port number of the server */
79018 union nf_inet_addr addr; /* IP address of the server */
79019 volatile unsigned int flags; /* dest status flags */
79020- atomic_t conn_flags; /* flags to copy to conn */
79021+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
79022 atomic_t weight; /* server weight */
79023
79024 atomic_t refcnt; /* reference counter */
79025@@ -1013,11 +1013,11 @@ struct netns_ipvs {
79026 /* ip_vs_lblc */
79027 int sysctl_lblc_expiration;
79028 struct ctl_table_header *lblc_ctl_header;
79029- struct ctl_table *lblc_ctl_table;
79030+ ctl_table_no_const *lblc_ctl_table;
79031 /* ip_vs_lblcr */
79032 int sysctl_lblcr_expiration;
79033 struct ctl_table_header *lblcr_ctl_header;
79034- struct ctl_table *lblcr_ctl_table;
79035+ ctl_table_no_const *lblcr_ctl_table;
79036 /* ip_vs_est */
79037 struct list_head est_list; /* estimator list */
79038 spinlock_t est_lock;
79039diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
79040index 80ffde3..968b0f4 100644
79041--- a/include/net/irda/ircomm_tty.h
79042+++ b/include/net/irda/ircomm_tty.h
79043@@ -35,6 +35,7 @@
79044 #include <linux/termios.h>
79045 #include <linux/timer.h>
79046 #include <linux/tty.h> /* struct tty_struct */
79047+#include <asm/local.h>
79048
79049 #include <net/irda/irias_object.h>
79050 #include <net/irda/ircomm_core.h>
79051diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
79052index 714cc9a..ea05f3e 100644
79053--- a/include/net/iucv/af_iucv.h
79054+++ b/include/net/iucv/af_iucv.h
79055@@ -149,7 +149,7 @@ struct iucv_skb_cb {
79056 struct iucv_sock_list {
79057 struct hlist_head head;
79058 rwlock_t lock;
79059- atomic_t autobind_name;
79060+ atomic_unchecked_t autobind_name;
79061 };
79062
79063 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
79064diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
79065index df83f69..9b640b8 100644
79066--- a/include/net/llc_c_ac.h
79067+++ b/include/net/llc_c_ac.h
79068@@ -87,7 +87,7 @@
79069 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
79070 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
79071
79072-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79073+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
79074
79075 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
79076 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
79077diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
79078index 6ca3113..f8026dd 100644
79079--- a/include/net/llc_c_ev.h
79080+++ b/include/net/llc_c_ev.h
79081@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
79082 return (struct llc_conn_state_ev *)skb->cb;
79083 }
79084
79085-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79086-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79087+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
79088+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
79089
79090 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
79091 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
79092diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
79093index 0e79cfb..f46db31 100644
79094--- a/include/net/llc_c_st.h
79095+++ b/include/net/llc_c_st.h
79096@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
79097 u8 next_state;
79098 llc_conn_ev_qfyr_t *ev_qualifiers;
79099 llc_conn_action_t *ev_actions;
79100-};
79101+} __do_const;
79102
79103 struct llc_conn_state {
79104 u8 current_state;
79105diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
79106index 37a3bbd..55a4241 100644
79107--- a/include/net/llc_s_ac.h
79108+++ b/include/net/llc_s_ac.h
79109@@ -23,7 +23,7 @@
79110 #define SAP_ACT_TEST_IND 9
79111
79112 /* All action functions must look like this */
79113-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79114+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
79115
79116 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
79117 struct sk_buff *skb);
79118diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
79119index 567c681..cd73ac0 100644
79120--- a/include/net/llc_s_st.h
79121+++ b/include/net/llc_s_st.h
79122@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
79123 llc_sap_ev_t ev;
79124 u8 next_state;
79125 llc_sap_action_t *ev_actions;
79126-};
79127+} __do_const;
79128
79129 struct llc_sap_state {
79130 u8 curr_state;
79131diff --git a/include/net/mac80211.h b/include/net/mac80211.h
79132index 885898a..cdace34 100644
79133--- a/include/net/mac80211.h
79134+++ b/include/net/mac80211.h
79135@@ -4205,7 +4205,7 @@ struct rate_control_ops {
79136 void (*add_sta_debugfs)(void *priv, void *priv_sta,
79137 struct dentry *dir);
79138 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
79139-};
79140+} __do_const;
79141
79142 static inline int rate_supported(struct ieee80211_sta *sta,
79143 enum ieee80211_band band,
79144diff --git a/include/net/neighbour.h b/include/net/neighbour.h
79145index 7e748ad..5c6229b 100644
79146--- a/include/net/neighbour.h
79147+++ b/include/net/neighbour.h
79148@@ -123,7 +123,7 @@ struct neigh_ops {
79149 void (*error_report)(struct neighbour *, struct sk_buff *);
79150 int (*output)(struct neighbour *, struct sk_buff *);
79151 int (*connected_output)(struct neighbour *, struct sk_buff *);
79152-};
79153+} __do_const;
79154
79155 struct pneigh_entry {
79156 struct pneigh_entry *next;
79157diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
79158index b176978..ea169f4 100644
79159--- a/include/net/net_namespace.h
79160+++ b/include/net/net_namespace.h
79161@@ -117,7 +117,7 @@ struct net {
79162 #endif
79163 struct netns_ipvs *ipvs;
79164 struct sock *diag_nlsk;
79165- atomic_t rt_genid;
79166+ atomic_unchecked_t rt_genid;
79167 };
79168
79169 /*
79170@@ -274,7 +274,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
79171 #define __net_init __init
79172 #define __net_exit __exit_refok
79173 #define __net_initdata __initdata
79174+#ifdef CONSTIFY_PLUGIN
79175 #define __net_initconst __initconst
79176+#else
79177+#define __net_initconst __initdata
79178+#endif
79179 #endif
79180
79181 struct pernet_operations {
79182@@ -284,7 +288,7 @@ struct pernet_operations {
79183 void (*exit_batch)(struct list_head *net_exit_list);
79184 int *id;
79185 size_t size;
79186-};
79187+} __do_const;
79188
79189 /*
79190 * Use these carefully. If you implement a network device and it
79191@@ -332,12 +336,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
79192
79193 static inline int rt_genid(struct net *net)
79194 {
79195- return atomic_read(&net->rt_genid);
79196+ return atomic_read_unchecked(&net->rt_genid);
79197 }
79198
79199 static inline void rt_genid_bump(struct net *net)
79200 {
79201- atomic_inc(&net->rt_genid);
79202+ atomic_inc_unchecked(&net->rt_genid);
79203 }
79204
79205 #endif /* __NET_NET_NAMESPACE_H */
79206diff --git a/include/net/netdma.h b/include/net/netdma.h
79207index 8ba8ce2..99b7fff 100644
79208--- a/include/net/netdma.h
79209+++ b/include/net/netdma.h
79210@@ -24,7 +24,7 @@
79211 #include <linux/dmaengine.h>
79212 #include <linux/skbuff.h>
79213
79214-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
79215+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
79216 struct sk_buff *skb, int offset, struct iovec *to,
79217 size_t len, struct dma_pinned_list *pinned_list);
79218
79219diff --git a/include/net/netlink.h b/include/net/netlink.h
79220index 9690b0f..87aded7 100644
79221--- a/include/net/netlink.h
79222+++ b/include/net/netlink.h
79223@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
79224 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
79225 {
79226 if (mark)
79227- skb_trim(skb, (unsigned char *) mark - skb->data);
79228+ skb_trim(skb, (const unsigned char *) mark - skb->data);
79229 }
79230
79231 /**
79232diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
79233index c9c0c53..53f24c3 100644
79234--- a/include/net/netns/conntrack.h
79235+++ b/include/net/netns/conntrack.h
79236@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
79237 struct nf_proto_net {
79238 #ifdef CONFIG_SYSCTL
79239 struct ctl_table_header *ctl_table_header;
79240- struct ctl_table *ctl_table;
79241+ ctl_table_no_const *ctl_table;
79242 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
79243 struct ctl_table_header *ctl_compat_header;
79244- struct ctl_table *ctl_compat_table;
79245+ ctl_table_no_const *ctl_compat_table;
79246 #endif
79247 #endif
79248 unsigned int users;
79249@@ -58,7 +58,7 @@ struct nf_ip_net {
79250 struct nf_icmp_net icmpv6;
79251 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
79252 struct ctl_table_header *ctl_table_header;
79253- struct ctl_table *ctl_table;
79254+ ctl_table_no_const *ctl_table;
79255 #endif
79256 };
79257
79258diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
79259index 2ba9de8..47bd6c7 100644
79260--- a/include/net/netns/ipv4.h
79261+++ b/include/net/netns/ipv4.h
79262@@ -67,7 +67,7 @@ struct netns_ipv4 {
79263 kgid_t sysctl_ping_group_range[2];
79264 long sysctl_tcp_mem[3];
79265
79266- atomic_t dev_addr_genid;
79267+ atomic_unchecked_t dev_addr_genid;
79268
79269 #ifdef CONFIG_IP_MROUTE
79270 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
79271diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
79272index 005e2c2..023d340 100644
79273--- a/include/net/netns/ipv6.h
79274+++ b/include/net/netns/ipv6.h
79275@@ -71,7 +71,7 @@ struct netns_ipv6 {
79276 struct fib_rules_ops *mr6_rules_ops;
79277 #endif
79278 #endif
79279- atomic_t dev_addr_genid;
79280+ atomic_unchecked_t dev_addr_genid;
79281 };
79282
79283 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
79284diff --git a/include/net/protocol.h b/include/net/protocol.h
79285index 047c047..b9dad15 100644
79286--- a/include/net/protocol.h
79287+++ b/include/net/protocol.h
79288@@ -44,7 +44,7 @@ struct net_protocol {
79289 void (*err_handler)(struct sk_buff *skb, u32 info);
79290 unsigned int no_policy:1,
79291 netns_ok:1;
79292-};
79293+} __do_const;
79294
79295 #if IS_ENABLED(CONFIG_IPV6)
79296 struct inet6_protocol {
79297@@ -57,7 +57,7 @@ struct inet6_protocol {
79298 u8 type, u8 code, int offset,
79299 __be32 info);
79300 unsigned int flags; /* INET6_PROTO_xxx */
79301-};
79302+} __do_const;
79303
79304 #define INET6_PROTO_NOPOLICY 0x1
79305 #define INET6_PROTO_FINAL 0x2
79306diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
79307index 7026648..584cc8c 100644
79308--- a/include/net/rtnetlink.h
79309+++ b/include/net/rtnetlink.h
79310@@ -81,7 +81,7 @@ struct rtnl_link_ops {
79311 const struct net_device *dev);
79312 unsigned int (*get_num_tx_queues)(void);
79313 unsigned int (*get_num_rx_queues)(void);
79314-};
79315+} __do_const;
79316
79317 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
79318 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
79319diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
79320index cd89510..d67810f 100644
79321--- a/include/net/sctp/sctp.h
79322+++ b/include/net/sctp/sctp.h
79323@@ -330,9 +330,9 @@ do { \
79324
79325 #else /* SCTP_DEBUG */
79326
79327-#define SCTP_DEBUG_PRINTK(whatever...)
79328-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
79329-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
79330+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
79331+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
79332+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
79333 #define SCTP_ENABLE_DEBUG
79334 #define SCTP_DISABLE_DEBUG
79335 #define SCTP_ASSERT(expr, str, func)
79336diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
79337index 2a82d13..62a31c2 100644
79338--- a/include/net/sctp/sm.h
79339+++ b/include/net/sctp/sm.h
79340@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
79341 typedef struct {
79342 sctp_state_fn_t *fn;
79343 const char *name;
79344-} sctp_sm_table_entry_t;
79345+} __do_const sctp_sm_table_entry_t;
79346
79347 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
79348 * currently in use.
79349@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
79350 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
79351
79352 /* Extern declarations for major data structures. */
79353-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79354+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79355
79356
79357 /* Get the size of a DATA chunk payload. */
79358diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
79359index 1bd4c41..9250b5b 100644
79360--- a/include/net/sctp/structs.h
79361+++ b/include/net/sctp/structs.h
79362@@ -516,7 +516,7 @@ struct sctp_pf {
79363 struct sctp_association *asoc);
79364 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
79365 struct sctp_af *af;
79366-};
79367+} __do_const;
79368
79369
79370 /* Structure to track chunk fragments that have been acked, but peer
79371diff --git a/include/net/sock.h b/include/net/sock.h
79372index 66772cf..25bc45b 100644
79373--- a/include/net/sock.h
79374+++ b/include/net/sock.h
79375@@ -325,7 +325,7 @@ struct sock {
79376 #ifdef CONFIG_RPS
79377 __u32 sk_rxhash;
79378 #endif
79379- atomic_t sk_drops;
79380+ atomic_unchecked_t sk_drops;
79381 int sk_rcvbuf;
79382
79383 struct sk_filter __rcu *sk_filter;
79384@@ -1797,7 +1797,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
79385 }
79386
79387 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
79388- char __user *from, char *to,
79389+ char __user *from, unsigned char *to,
79390 int copy, int offset)
79391 {
79392 if (skb->ip_summed == CHECKSUM_NONE) {
79393@@ -2056,7 +2056,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
79394 }
79395 }
79396
79397-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79398+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79399
79400 /**
79401 * sk_page_frag - return an appropriate page_frag
79402diff --git a/include/net/tcp.h b/include/net/tcp.h
79403index 5bba80f..8520a82 100644
79404--- a/include/net/tcp.h
79405+++ b/include/net/tcp.h
79406@@ -524,7 +524,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
79407 extern void tcp_xmit_retransmit_queue(struct sock *);
79408 extern void tcp_simple_retransmit(struct sock *);
79409 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
79410-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79411+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79412
79413 extern void tcp_send_probe0(struct sock *);
79414 extern void tcp_send_partial(struct sock *);
79415@@ -697,8 +697,8 @@ struct tcp_skb_cb {
79416 struct inet6_skb_parm h6;
79417 #endif
79418 } header; /* For incoming frames */
79419- __u32 seq; /* Starting sequence number */
79420- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
79421+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
79422+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
79423 __u32 when; /* used to compute rtt's */
79424 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
79425
79426@@ -712,7 +712,7 @@ struct tcp_skb_cb {
79427
79428 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
79429 /* 1 byte hole */
79430- __u32 ack_seq; /* Sequence number ACK'd */
79431+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
79432 };
79433
79434 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
79435diff --git a/include/net/xfrm.h b/include/net/xfrm.h
79436index 94ce082..62b278d 100644
79437--- a/include/net/xfrm.h
79438+++ b/include/net/xfrm.h
79439@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
79440 struct net_device *dev,
79441 const struct flowi *fl);
79442 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
79443-};
79444+} __do_const;
79445
79446 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
79447 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
79448@@ -341,7 +341,7 @@ struct xfrm_state_afinfo {
79449 struct sk_buff *skb);
79450 int (*transport_finish)(struct sk_buff *skb,
79451 int async);
79452-};
79453+} __do_const;
79454
79455 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
79456 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
79457@@ -424,7 +424,7 @@ struct xfrm_mode {
79458 struct module *owner;
79459 unsigned int encap;
79460 int flags;
79461-};
79462+} __do_const;
79463
79464 /* Flags for xfrm_mode. */
79465 enum {
79466@@ -521,7 +521,7 @@ struct xfrm_policy {
79467 struct timer_list timer;
79468
79469 struct flow_cache_object flo;
79470- atomic_t genid;
79471+ atomic_unchecked_t genid;
79472 u32 priority;
79473 u32 index;
79474 struct xfrm_mark mark;
79475diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
79476index 1a046b1..ee0bef0 100644
79477--- a/include/rdma/iw_cm.h
79478+++ b/include/rdma/iw_cm.h
79479@@ -122,7 +122,7 @@ struct iw_cm_verbs {
79480 int backlog);
79481
79482 int (*destroy_listen)(struct iw_cm_id *cm_id);
79483-};
79484+} __no_const;
79485
79486 /**
79487 * iw_create_cm_id - Create an IW CM identifier.
79488diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
79489index e1379b4..67eafbe 100644
79490--- a/include/scsi/libfc.h
79491+++ b/include/scsi/libfc.h
79492@@ -762,6 +762,7 @@ struct libfc_function_template {
79493 */
79494 void (*disc_stop_final) (struct fc_lport *);
79495 };
79496+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
79497
79498 /**
79499 * struct fc_disc - Discovery context
79500@@ -866,7 +867,7 @@ struct fc_lport {
79501 struct fc_vport *vport;
79502
79503 /* Operational Information */
79504- struct libfc_function_template tt;
79505+ libfc_function_template_no_const tt;
79506 u8 link_up;
79507 u8 qfull;
79508 enum fc_lport_state state;
79509diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
79510index cc64587..608f523 100644
79511--- a/include/scsi/scsi_device.h
79512+++ b/include/scsi/scsi_device.h
79513@@ -171,9 +171,9 @@ struct scsi_device {
79514 unsigned int max_device_blocked; /* what device_blocked counts down from */
79515 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
79516
79517- atomic_t iorequest_cnt;
79518- atomic_t iodone_cnt;
79519- atomic_t ioerr_cnt;
79520+ atomic_unchecked_t iorequest_cnt;
79521+ atomic_unchecked_t iodone_cnt;
79522+ atomic_unchecked_t ioerr_cnt;
79523
79524 struct device sdev_gendev,
79525 sdev_dev;
79526diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
79527index b797e8f..8e2c3aa 100644
79528--- a/include/scsi/scsi_transport_fc.h
79529+++ b/include/scsi/scsi_transport_fc.h
79530@@ -751,7 +751,8 @@ struct fc_function_template {
79531 unsigned long show_host_system_hostname:1;
79532
79533 unsigned long disable_target_scan:1;
79534-};
79535+} __do_const;
79536+typedef struct fc_function_template __no_const fc_function_template_no_const;
79537
79538
79539 /**
79540diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
79541index 9031a26..750d592 100644
79542--- a/include/sound/compress_driver.h
79543+++ b/include/sound/compress_driver.h
79544@@ -128,7 +128,7 @@ struct snd_compr_ops {
79545 struct snd_compr_caps *caps);
79546 int (*get_codec_caps) (struct snd_compr_stream *stream,
79547 struct snd_compr_codec_caps *codec);
79548-};
79549+} __no_const;
79550
79551 /**
79552 * struct snd_compr: Compressed device
79553diff --git a/include/sound/soc.h b/include/sound/soc.h
79554index 85c1522..f44bad1 100644
79555--- a/include/sound/soc.h
79556+++ b/include/sound/soc.h
79557@@ -781,7 +781,7 @@ struct snd_soc_codec_driver {
79558 /* probe ordering - for components with runtime dependencies */
79559 int probe_order;
79560 int remove_order;
79561-};
79562+} __do_const;
79563
79564 /* SoC platform interface */
79565 struct snd_soc_platform_driver {
79566@@ -827,7 +827,7 @@ struct snd_soc_platform_driver {
79567 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
79568 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
79569 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
79570-};
79571+} __do_const;
79572
79573 struct snd_soc_platform {
79574 const char *name;
79575diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
79576index 4ea4f98..a63629b 100644
79577--- a/include/target/target_core_base.h
79578+++ b/include/target/target_core_base.h
79579@@ -653,7 +653,7 @@ struct se_device {
79580 spinlock_t stats_lock;
79581 /* Active commands on this virtual SE device */
79582 atomic_t simple_cmds;
79583- atomic_t dev_ordered_id;
79584+ atomic_unchecked_t dev_ordered_id;
79585 atomic_t dev_ordered_sync;
79586 atomic_t dev_qf_count;
79587 int export_count;
79588diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
79589new file mode 100644
79590index 0000000..fb634b7
79591--- /dev/null
79592+++ b/include/trace/events/fs.h
79593@@ -0,0 +1,53 @@
79594+#undef TRACE_SYSTEM
79595+#define TRACE_SYSTEM fs
79596+
79597+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
79598+#define _TRACE_FS_H
79599+
79600+#include <linux/fs.h>
79601+#include <linux/tracepoint.h>
79602+
79603+TRACE_EVENT(do_sys_open,
79604+
79605+ TP_PROTO(const char *filename, int flags, int mode),
79606+
79607+ TP_ARGS(filename, flags, mode),
79608+
79609+ TP_STRUCT__entry(
79610+ __string( filename, filename )
79611+ __field( int, flags )
79612+ __field( int, mode )
79613+ ),
79614+
79615+ TP_fast_assign(
79616+ __assign_str(filename, filename);
79617+ __entry->flags = flags;
79618+ __entry->mode = mode;
79619+ ),
79620+
79621+ TP_printk("\"%s\" %x %o",
79622+ __get_str(filename), __entry->flags, __entry->mode)
79623+);
79624+
79625+TRACE_EVENT(open_exec,
79626+
79627+ TP_PROTO(const char *filename),
79628+
79629+ TP_ARGS(filename),
79630+
79631+ TP_STRUCT__entry(
79632+ __string( filename, filename )
79633+ ),
79634+
79635+ TP_fast_assign(
79636+ __assign_str(filename, filename);
79637+ ),
79638+
79639+ TP_printk("\"%s\"",
79640+ __get_str(filename))
79641+);
79642+
79643+#endif /* _TRACE_FS_H */
79644+
79645+/* This part must be outside protection */
79646+#include <trace/define_trace.h>
79647diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
79648index 1c09820..7f5ec79 100644
79649--- a/include/trace/events/irq.h
79650+++ b/include/trace/events/irq.h
79651@@ -36,7 +36,7 @@ struct softirq_action;
79652 */
79653 TRACE_EVENT(irq_handler_entry,
79654
79655- TP_PROTO(int irq, struct irqaction *action),
79656+ TP_PROTO(int irq, const struct irqaction *action),
79657
79658 TP_ARGS(irq, action),
79659
79660@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
79661 */
79662 TRACE_EVENT(irq_handler_exit,
79663
79664- TP_PROTO(int irq, struct irqaction *action, int ret),
79665+ TP_PROTO(int irq, const struct irqaction *action, int ret),
79666
79667 TP_ARGS(irq, action, ret),
79668
79669diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
79670index 7caf44c..23c6f27 100644
79671--- a/include/uapi/linux/a.out.h
79672+++ b/include/uapi/linux/a.out.h
79673@@ -39,6 +39,14 @@ enum machine_type {
79674 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
79675 };
79676
79677+/* Constants for the N_FLAGS field */
79678+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79679+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
79680+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
79681+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
79682+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79683+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79684+
79685 #if !defined (N_MAGIC)
79686 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
79687 #endif
79688diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
79689index d876736..ccce5c0 100644
79690--- a/include/uapi/linux/byteorder/little_endian.h
79691+++ b/include/uapi/linux/byteorder/little_endian.h
79692@@ -42,51 +42,51 @@
79693
79694 static inline __le64 __cpu_to_le64p(const __u64 *p)
79695 {
79696- return (__force __le64)*p;
79697+ return (__force const __le64)*p;
79698 }
79699-static inline __u64 __le64_to_cpup(const __le64 *p)
79700+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
79701 {
79702- return (__force __u64)*p;
79703+ return (__force const __u64)*p;
79704 }
79705 static inline __le32 __cpu_to_le32p(const __u32 *p)
79706 {
79707- return (__force __le32)*p;
79708+ return (__force const __le32)*p;
79709 }
79710 static inline __u32 __le32_to_cpup(const __le32 *p)
79711 {
79712- return (__force __u32)*p;
79713+ return (__force const __u32)*p;
79714 }
79715 static inline __le16 __cpu_to_le16p(const __u16 *p)
79716 {
79717- return (__force __le16)*p;
79718+ return (__force const __le16)*p;
79719 }
79720 static inline __u16 __le16_to_cpup(const __le16 *p)
79721 {
79722- return (__force __u16)*p;
79723+ return (__force const __u16)*p;
79724 }
79725 static inline __be64 __cpu_to_be64p(const __u64 *p)
79726 {
79727- return (__force __be64)__swab64p(p);
79728+ return (__force const __be64)__swab64p(p);
79729 }
79730 static inline __u64 __be64_to_cpup(const __be64 *p)
79731 {
79732- return __swab64p((__u64 *)p);
79733+ return __swab64p((const __u64 *)p);
79734 }
79735 static inline __be32 __cpu_to_be32p(const __u32 *p)
79736 {
79737- return (__force __be32)__swab32p(p);
79738+ return (__force const __be32)__swab32p(p);
79739 }
79740-static inline __u32 __be32_to_cpup(const __be32 *p)
79741+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
79742 {
79743- return __swab32p((__u32 *)p);
79744+ return __swab32p((const __u32 *)p);
79745 }
79746 static inline __be16 __cpu_to_be16p(const __u16 *p)
79747 {
79748- return (__force __be16)__swab16p(p);
79749+ return (__force const __be16)__swab16p(p);
79750 }
79751 static inline __u16 __be16_to_cpup(const __be16 *p)
79752 {
79753- return __swab16p((__u16 *)p);
79754+ return __swab16p((const __u16 *)p);
79755 }
79756 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
79757 #define __le64_to_cpus(x) do { (void)(x); } while (0)
79758diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
79759index ef6103b..d4e65dd 100644
79760--- a/include/uapi/linux/elf.h
79761+++ b/include/uapi/linux/elf.h
79762@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
79763 #define PT_GNU_EH_FRAME 0x6474e550
79764
79765 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
79766+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
79767+
79768+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
79769+
79770+/* Constants for the e_flags field */
79771+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79772+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
79773+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
79774+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
79775+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79776+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79777
79778 /*
79779 * Extended Numbering
79780@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
79781 #define DT_DEBUG 21
79782 #define DT_TEXTREL 22
79783 #define DT_JMPREL 23
79784+#define DT_FLAGS 30
79785+ #define DF_TEXTREL 0x00000004
79786 #define DT_ENCODING 32
79787 #define OLD_DT_LOOS 0x60000000
79788 #define DT_LOOS 0x6000000d
79789@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
79790 #define PF_W 0x2
79791 #define PF_X 0x1
79792
79793+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
79794+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
79795+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
79796+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
79797+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
79798+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
79799+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
79800+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
79801+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
79802+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
79803+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
79804+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
79805+
79806 typedef struct elf32_phdr{
79807 Elf32_Word p_type;
79808 Elf32_Off p_offset;
79809@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
79810 #define EI_OSABI 7
79811 #define EI_PAD 8
79812
79813+#define EI_PAX 14
79814+
79815 #define ELFMAG0 0x7f /* EI_MAG */
79816 #define ELFMAG1 'E'
79817 #define ELFMAG2 'L'
79818diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
79819index aa169c4..6a2771d 100644
79820--- a/include/uapi/linux/personality.h
79821+++ b/include/uapi/linux/personality.h
79822@@ -30,6 +30,7 @@ enum {
79823 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
79824 ADDR_NO_RANDOMIZE | \
79825 ADDR_COMPAT_LAYOUT | \
79826+ ADDR_LIMIT_3GB | \
79827 MMAP_PAGE_ZERO)
79828
79829 /*
79830diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
79831index 7530e74..e714828 100644
79832--- a/include/uapi/linux/screen_info.h
79833+++ b/include/uapi/linux/screen_info.h
79834@@ -43,7 +43,8 @@ struct screen_info {
79835 __u16 pages; /* 0x32 */
79836 __u16 vesa_attributes; /* 0x34 */
79837 __u32 capabilities; /* 0x36 */
79838- __u8 _reserved[6]; /* 0x3a */
79839+ __u16 vesapm_size; /* 0x3a */
79840+ __u8 _reserved[4]; /* 0x3c */
79841 } __attribute__((packed));
79842
79843 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
79844diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
79845index 0e011eb..82681b1 100644
79846--- a/include/uapi/linux/swab.h
79847+++ b/include/uapi/linux/swab.h
79848@@ -43,7 +43,7 @@
79849 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
79850 */
79851
79852-static inline __attribute_const__ __u16 __fswab16(__u16 val)
79853+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
79854 {
79855 #ifdef __HAVE_BUILTIN_BSWAP16__
79856 return __builtin_bswap16(val);
79857@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
79858 #endif
79859 }
79860
79861-static inline __attribute_const__ __u32 __fswab32(__u32 val)
79862+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
79863 {
79864 #ifdef __HAVE_BUILTIN_BSWAP32__
79865 return __builtin_bswap32(val);
79866@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
79867 #endif
79868 }
79869
79870-static inline __attribute_const__ __u64 __fswab64(__u64 val)
79871+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
79872 {
79873 #ifdef __HAVE_BUILTIN_BSWAP64__
79874 return __builtin_bswap64(val);
79875diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
79876index 6d67213..8dab561 100644
79877--- a/include/uapi/linux/sysctl.h
79878+++ b/include/uapi/linux/sysctl.h
79879@@ -155,7 +155,11 @@ enum
79880 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
79881 };
79882
79883-
79884+#ifdef CONFIG_PAX_SOFTMODE
79885+enum {
79886+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
79887+};
79888+#endif
79889
79890 /* CTL_VM names: */
79891 enum
79892diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
79893index e4629b9..6958086 100644
79894--- a/include/uapi/linux/xattr.h
79895+++ b/include/uapi/linux/xattr.h
79896@@ -63,5 +63,9 @@
79897 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
79898 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
79899
79900+/* User namespace */
79901+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
79902+#define XATTR_PAX_FLAGS_SUFFIX "flags"
79903+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
79904
79905 #endif /* _UAPI_LINUX_XATTR_H */
79906diff --git a/include/video/udlfb.h b/include/video/udlfb.h
79907index f9466fa..f4e2b81 100644
79908--- a/include/video/udlfb.h
79909+++ b/include/video/udlfb.h
79910@@ -53,10 +53,10 @@ struct dlfb_data {
79911 u32 pseudo_palette[256];
79912 int blank_mode; /*one of FB_BLANK_ */
79913 /* blit-only rendering path metrics, exposed through sysfs */
79914- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79915- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
79916- atomic_t bytes_sent; /* to usb, after compression including overhead */
79917- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
79918+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79919+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
79920+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
79921+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
79922 };
79923
79924 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
79925diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
79926index 1a91850..28573f8 100644
79927--- a/include/video/uvesafb.h
79928+++ b/include/video/uvesafb.h
79929@@ -122,6 +122,7 @@ struct uvesafb_par {
79930 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
79931 u8 pmi_setpal; /* PMI for palette changes */
79932 u16 *pmi_base; /* protected mode interface location */
79933+ u8 *pmi_code; /* protected mode code location */
79934 void *pmi_start;
79935 void *pmi_pal;
79936 u8 *vbe_state_orig; /*
79937diff --git a/init/Kconfig b/init/Kconfig
79938index 2d9b831..ae4c8ac 100644
79939--- a/init/Kconfig
79940+++ b/init/Kconfig
79941@@ -1029,6 +1029,7 @@ endif # CGROUPS
79942
79943 config CHECKPOINT_RESTORE
79944 bool "Checkpoint/restore support" if EXPERT
79945+ depends on !GRKERNSEC
79946 default n
79947 help
79948 Enables additional kernel features in a sake of checkpoint/restore.
79949@@ -1516,7 +1517,7 @@ config SLUB_DEBUG
79950
79951 config COMPAT_BRK
79952 bool "Disable heap randomization"
79953- default y
79954+ default n
79955 help
79956 Randomizing heap placement makes heap exploits harder, but it
79957 also breaks ancient binaries (including anything libc5 based).
79958@@ -1779,7 +1780,7 @@ config INIT_ALL_POSSIBLE
79959 config STOP_MACHINE
79960 bool
79961 default y
79962- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
79963+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
79964 help
79965 Need stop_machine() primitive.
79966
79967diff --git a/init/Makefile b/init/Makefile
79968index 7bc47ee..6da2dc7 100644
79969--- a/init/Makefile
79970+++ b/init/Makefile
79971@@ -2,6 +2,9 @@
79972 # Makefile for the linux kernel.
79973 #
79974
79975+ccflags-y := $(GCC_PLUGINS_CFLAGS)
79976+asflags-y := $(GCC_PLUGINS_AFLAGS)
79977+
79978 obj-y := main.o version.o mounts.o
79979 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
79980 obj-y += noinitramfs.o
79981diff --git a/init/do_mounts.c b/init/do_mounts.c
79982index a2b49f2..03a0e17c 100644
79983--- a/init/do_mounts.c
79984+++ b/init/do_mounts.c
79985@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
79986 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
79987 {
79988 struct super_block *s;
79989- int err = sys_mount(name, "/root", fs, flags, data);
79990+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
79991 if (err)
79992 return err;
79993
79994- sys_chdir("/root");
79995+ sys_chdir((const char __force_user *)"/root");
79996 s = current->fs->pwd.dentry->d_sb;
79997 ROOT_DEV = s->s_dev;
79998 printk(KERN_INFO
79999@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
80000 va_start(args, fmt);
80001 vsprintf(buf, fmt, args);
80002 va_end(args);
80003- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
80004+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
80005 if (fd >= 0) {
80006 sys_ioctl(fd, FDEJECT, 0);
80007 sys_close(fd);
80008 }
80009 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
80010- fd = sys_open("/dev/console", O_RDWR, 0);
80011+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
80012 if (fd >= 0) {
80013 sys_ioctl(fd, TCGETS, (long)&termios);
80014 termios.c_lflag &= ~ICANON;
80015 sys_ioctl(fd, TCSETSF, (long)&termios);
80016- sys_read(fd, &c, 1);
80017+ sys_read(fd, (char __user *)&c, 1);
80018 termios.c_lflag |= ICANON;
80019 sys_ioctl(fd, TCSETSF, (long)&termios);
80020 sys_close(fd);
80021@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
80022 mount_root();
80023 out:
80024 devtmpfs_mount("dev");
80025- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80026- sys_chroot(".");
80027+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80028+ sys_chroot((const char __force_user *)".");
80029 }
80030diff --git a/init/do_mounts.h b/init/do_mounts.h
80031index f5b978a..69dbfe8 100644
80032--- a/init/do_mounts.h
80033+++ b/init/do_mounts.h
80034@@ -15,15 +15,15 @@ extern int root_mountflags;
80035
80036 static inline int create_dev(char *name, dev_t dev)
80037 {
80038- sys_unlink(name);
80039- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
80040+ sys_unlink((char __force_user *)name);
80041+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
80042 }
80043
80044 #if BITS_PER_LONG == 32
80045 static inline u32 bstat(char *name)
80046 {
80047 struct stat64 stat;
80048- if (sys_stat64(name, &stat) != 0)
80049+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
80050 return 0;
80051 if (!S_ISBLK(stat.st_mode))
80052 return 0;
80053@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
80054 static inline u32 bstat(char *name)
80055 {
80056 struct stat stat;
80057- if (sys_newstat(name, &stat) != 0)
80058+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
80059 return 0;
80060 if (!S_ISBLK(stat.st_mode))
80061 return 0;
80062diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
80063index 3e0878e..8a9d7a0 100644
80064--- a/init/do_mounts_initrd.c
80065+++ b/init/do_mounts_initrd.c
80066@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
80067 {
80068 sys_unshare(CLONE_FS | CLONE_FILES);
80069 /* stdin/stdout/stderr for /linuxrc */
80070- sys_open("/dev/console", O_RDWR, 0);
80071+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
80072 sys_dup(0);
80073 sys_dup(0);
80074 /* move initrd over / and chdir/chroot in initrd root */
80075- sys_chdir("/root");
80076- sys_mount(".", "/", NULL, MS_MOVE, NULL);
80077- sys_chroot(".");
80078+ sys_chdir((const char __force_user *)"/root");
80079+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
80080+ sys_chroot((const char __force_user *)".");
80081 sys_setsid();
80082 return 0;
80083 }
80084@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
80085 create_dev("/dev/root.old", Root_RAM0);
80086 /* mount initrd on rootfs' /root */
80087 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
80088- sys_mkdir("/old", 0700);
80089- sys_chdir("/old");
80090+ sys_mkdir((const char __force_user *)"/old", 0700);
80091+ sys_chdir((const char __force_user *)"/old");
80092
80093 /* try loading default modules from initrd */
80094 load_default_modules();
80095@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
80096 current->flags &= ~PF_FREEZER_SKIP;
80097
80098 /* move initrd to rootfs' /old */
80099- sys_mount("..", ".", NULL, MS_MOVE, NULL);
80100+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
80101 /* switch root and cwd back to / of rootfs */
80102- sys_chroot("..");
80103+ sys_chroot((const char __force_user *)"..");
80104
80105 if (new_decode_dev(real_root_dev) == Root_RAM0) {
80106- sys_chdir("/old");
80107+ sys_chdir((const char __force_user *)"/old");
80108 return;
80109 }
80110
80111- sys_chdir("/");
80112+ sys_chdir((const char __force_user *)"/");
80113 ROOT_DEV = new_decode_dev(real_root_dev);
80114 mount_root();
80115
80116 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
80117- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
80118+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
80119 if (!error)
80120 printk("okay\n");
80121 else {
80122- int fd = sys_open("/dev/root.old", O_RDWR, 0);
80123+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
80124 if (error == -ENOENT)
80125 printk("/initrd does not exist. Ignored.\n");
80126 else
80127 printk("failed\n");
80128 printk(KERN_NOTICE "Unmounting old root\n");
80129- sys_umount("/old", MNT_DETACH);
80130+ sys_umount((char __force_user *)"/old", MNT_DETACH);
80131 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
80132 if (fd < 0) {
80133 error = fd;
80134@@ -127,11 +127,11 @@ int __init initrd_load(void)
80135 * mounted in the normal path.
80136 */
80137 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
80138- sys_unlink("/initrd.image");
80139+ sys_unlink((const char __force_user *)"/initrd.image");
80140 handle_initrd();
80141 return 1;
80142 }
80143 }
80144- sys_unlink("/initrd.image");
80145+ sys_unlink((const char __force_user *)"/initrd.image");
80146 return 0;
80147 }
80148diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
80149index 8cb6db5..d729f50 100644
80150--- a/init/do_mounts_md.c
80151+++ b/init/do_mounts_md.c
80152@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
80153 partitioned ? "_d" : "", minor,
80154 md_setup_args[ent].device_names);
80155
80156- fd = sys_open(name, 0, 0);
80157+ fd = sys_open((char __force_user *)name, 0, 0);
80158 if (fd < 0) {
80159 printk(KERN_ERR "md: open failed - cannot start "
80160 "array %s\n", name);
80161@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
80162 * array without it
80163 */
80164 sys_close(fd);
80165- fd = sys_open(name, 0, 0);
80166+ fd = sys_open((char __force_user *)name, 0, 0);
80167 sys_ioctl(fd, BLKRRPART, 0);
80168 }
80169 sys_close(fd);
80170@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
80171
80172 wait_for_device_probe();
80173
80174- fd = sys_open("/dev/md0", 0, 0);
80175+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
80176 if (fd >= 0) {
80177 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
80178 sys_close(fd);
80179diff --git a/init/init_task.c b/init/init_task.c
80180index ba0a7f36..2bcf1d5 100644
80181--- a/init/init_task.c
80182+++ b/init/init_task.c
80183@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
80184 * Initial thread structure. Alignment of this is handled by a special
80185 * linker map entry.
80186 */
80187+#ifdef CONFIG_X86
80188+union thread_union init_thread_union __init_task_data;
80189+#else
80190 union thread_union init_thread_union __init_task_data =
80191 { INIT_THREAD_INFO(init_task) };
80192+#endif
80193diff --git a/init/initramfs.c b/init/initramfs.c
80194index a67ef9d..2d17ed9 100644
80195--- a/init/initramfs.c
80196+++ b/init/initramfs.c
80197@@ -84,7 +84,7 @@ static void __init free_hash(void)
80198 }
80199 }
80200
80201-static long __init do_utime(char *filename, time_t mtime)
80202+static long __init do_utime(char __force_user *filename, time_t mtime)
80203 {
80204 struct timespec t[2];
80205
80206@@ -119,7 +119,7 @@ static void __init dir_utime(void)
80207 struct dir_entry *de, *tmp;
80208 list_for_each_entry_safe(de, tmp, &dir_list, list) {
80209 list_del(&de->list);
80210- do_utime(de->name, de->mtime);
80211+ do_utime((char __force_user *)de->name, de->mtime);
80212 kfree(de->name);
80213 kfree(de);
80214 }
80215@@ -281,7 +281,7 @@ static int __init maybe_link(void)
80216 if (nlink >= 2) {
80217 char *old = find_link(major, minor, ino, mode, collected);
80218 if (old)
80219- return (sys_link(old, collected) < 0) ? -1 : 1;
80220+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
80221 }
80222 return 0;
80223 }
80224@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
80225 {
80226 struct stat st;
80227
80228- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
80229+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
80230 if (S_ISDIR(st.st_mode))
80231- sys_rmdir(path);
80232+ sys_rmdir((char __force_user *)path);
80233 else
80234- sys_unlink(path);
80235+ sys_unlink((char __force_user *)path);
80236 }
80237 }
80238
80239@@ -315,7 +315,7 @@ static int __init do_name(void)
80240 int openflags = O_WRONLY|O_CREAT;
80241 if (ml != 1)
80242 openflags |= O_TRUNC;
80243- wfd = sys_open(collected, openflags, mode);
80244+ wfd = sys_open((char __force_user *)collected, openflags, mode);
80245
80246 if (wfd >= 0) {
80247 sys_fchown(wfd, uid, gid);
80248@@ -327,17 +327,17 @@ static int __init do_name(void)
80249 }
80250 }
80251 } else if (S_ISDIR(mode)) {
80252- sys_mkdir(collected, mode);
80253- sys_chown(collected, uid, gid);
80254- sys_chmod(collected, mode);
80255+ sys_mkdir((char __force_user *)collected, mode);
80256+ sys_chown((char __force_user *)collected, uid, gid);
80257+ sys_chmod((char __force_user *)collected, mode);
80258 dir_add(collected, mtime);
80259 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
80260 S_ISFIFO(mode) || S_ISSOCK(mode)) {
80261 if (maybe_link() == 0) {
80262- sys_mknod(collected, mode, rdev);
80263- sys_chown(collected, uid, gid);
80264- sys_chmod(collected, mode);
80265- do_utime(collected, mtime);
80266+ sys_mknod((char __force_user *)collected, mode, rdev);
80267+ sys_chown((char __force_user *)collected, uid, gid);
80268+ sys_chmod((char __force_user *)collected, mode);
80269+ do_utime((char __force_user *)collected, mtime);
80270 }
80271 }
80272 return 0;
80273@@ -346,15 +346,15 @@ static int __init do_name(void)
80274 static int __init do_copy(void)
80275 {
80276 if (count >= body_len) {
80277- sys_write(wfd, victim, body_len);
80278+ sys_write(wfd, (char __force_user *)victim, body_len);
80279 sys_close(wfd);
80280- do_utime(vcollected, mtime);
80281+ do_utime((char __force_user *)vcollected, mtime);
80282 kfree(vcollected);
80283 eat(body_len);
80284 state = SkipIt;
80285 return 0;
80286 } else {
80287- sys_write(wfd, victim, count);
80288+ sys_write(wfd, (char __force_user *)victim, count);
80289 body_len -= count;
80290 eat(count);
80291 return 1;
80292@@ -365,9 +365,9 @@ static int __init do_symlink(void)
80293 {
80294 collected[N_ALIGN(name_len) + body_len] = '\0';
80295 clean_path(collected, 0);
80296- sys_symlink(collected + N_ALIGN(name_len), collected);
80297- sys_lchown(collected, uid, gid);
80298- do_utime(collected, mtime);
80299+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
80300+ sys_lchown((char __force_user *)collected, uid, gid);
80301+ do_utime((char __force_user *)collected, mtime);
80302 state = SkipIt;
80303 next_state = Reset;
80304 return 0;
80305@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
80306 {
80307 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
80308 if (err)
80309- panic(err); /* Failed to decompress INTERNAL initramfs */
80310+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
80311 if (initrd_start) {
80312 #ifdef CONFIG_BLK_DEV_RAM
80313 int fd;
80314diff --git a/init/main.c b/init/main.c
80315index 9484f4b..0eac7c3 100644
80316--- a/init/main.c
80317+++ b/init/main.c
80318@@ -100,6 +100,8 @@ static inline void mark_rodata_ro(void) { }
80319 extern void tc_init(void);
80320 #endif
80321
80322+extern void grsecurity_init(void);
80323+
80324 /*
80325 * Debug helper: via this flag we know that we are in 'early bootup code'
80326 * where only the boot processor is running with IRQ disabled. This means
80327@@ -153,6 +155,74 @@ static int __init set_reset_devices(char *str)
80328
80329 __setup("reset_devices", set_reset_devices);
80330
80331+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80332+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
80333+static int __init setup_grsec_proc_gid(char *str)
80334+{
80335+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
80336+ return 1;
80337+}
80338+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
80339+#endif
80340+
80341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
80342+unsigned long pax_user_shadow_base __read_only;
80343+EXPORT_SYMBOL(pax_user_shadow_base);
80344+extern char pax_enter_kernel_user[];
80345+extern char pax_exit_kernel_user[];
80346+#endif
80347+
80348+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
80349+static int __init setup_pax_nouderef(char *str)
80350+{
80351+#ifdef CONFIG_X86_32
80352+ unsigned int cpu;
80353+ struct desc_struct *gdt;
80354+
80355+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
80356+ gdt = get_cpu_gdt_table(cpu);
80357+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
80358+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
80359+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
80360+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
80361+ }
80362+ loadsegment(ds, __KERNEL_DS);
80363+ loadsegment(es, __KERNEL_DS);
80364+ loadsegment(ss, __KERNEL_DS);
80365+#else
80366+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
80367+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
80368+ clone_pgd_mask = ~(pgdval_t)0UL;
80369+ pax_user_shadow_base = 0UL;
80370+ setup_clear_cpu_cap(X86_FEATURE_PCID);
80371+#endif
80372+
80373+ return 0;
80374+}
80375+early_param("pax_nouderef", setup_pax_nouderef);
80376+
80377+#ifdef CONFIG_X86_64
80378+static int __init setup_pax_weakuderef(char *str)
80379+{
80380+ if (clone_pgd_mask != ~(pgdval_t)0UL)
80381+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
80382+ return 1;
80383+}
80384+__setup("pax_weakuderef", setup_pax_weakuderef);
80385+#endif
80386+#endif
80387+
80388+#ifdef CONFIG_PAX_SOFTMODE
80389+int pax_softmode;
80390+
80391+static int __init setup_pax_softmode(char *str)
80392+{
80393+ get_option(&str, &pax_softmode);
80394+ return 1;
80395+}
80396+__setup("pax_softmode=", setup_pax_softmode);
80397+#endif
80398+
80399 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
80400 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
80401 static const char *panic_later, *panic_param;
80402@@ -655,8 +725,6 @@ static void __init do_ctors(void)
80403 bool initcall_debug;
80404 core_param(initcall_debug, initcall_debug, bool, 0644);
80405
80406-static char msgbuf[64];
80407-
80408 static int __init_or_module do_one_initcall_debug(initcall_t fn)
80409 {
80410 ktime_t calltime, delta, rettime;
80411@@ -679,23 +747,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
80412 {
80413 int count = preempt_count();
80414 int ret;
80415+ const char *msg1 = "", *msg2 = "";
80416
80417 if (initcall_debug)
80418 ret = do_one_initcall_debug(fn);
80419 else
80420 ret = fn();
80421
80422- msgbuf[0] = 0;
80423-
80424 if (preempt_count() != count) {
80425- sprintf(msgbuf, "preemption imbalance ");
80426+ msg1 = " preemption imbalance";
80427 preempt_count() = count;
80428 }
80429 if (irqs_disabled()) {
80430- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
80431+ msg2 = " disabled interrupts";
80432 local_irq_enable();
80433 }
80434- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
80435+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
80436
80437 return ret;
80438 }
80439@@ -748,8 +815,14 @@ static void __init do_initcall_level(int level)
80440 level, level,
80441 &repair_env_string);
80442
80443- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
80444+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
80445 do_one_initcall(*fn);
80446+
80447+#ifdef LATENT_ENTROPY_PLUGIN
80448+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80449+#endif
80450+
80451+ }
80452 }
80453
80454 static void __init do_initcalls(void)
80455@@ -783,8 +856,14 @@ static void __init do_pre_smp_initcalls(void)
80456 {
80457 initcall_t *fn;
80458
80459- for (fn = __initcall_start; fn < __initcall0_start; fn++)
80460+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
80461 do_one_initcall(*fn);
80462+
80463+#ifdef LATENT_ENTROPY_PLUGIN
80464+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80465+#endif
80466+
80467+ }
80468 }
80469
80470 /*
80471@@ -802,8 +881,8 @@ static int run_init_process(const char *init_filename)
80472 {
80473 argv_init[0] = init_filename;
80474 return do_execve(init_filename,
80475- (const char __user *const __user *)argv_init,
80476- (const char __user *const __user *)envp_init);
80477+ (const char __user *const __force_user *)argv_init,
80478+ (const char __user *const __force_user *)envp_init);
80479 }
80480
80481 static noinline void __init kernel_init_freeable(void);
80482@@ -880,7 +959,7 @@ static noinline void __init kernel_init_freeable(void)
80483 do_basic_setup();
80484
80485 /* Open the /dev/console on the rootfs, this should never fail */
80486- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
80487+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
80488 pr_err("Warning: unable to open an initial console.\n");
80489
80490 (void) sys_dup(0);
80491@@ -893,11 +972,13 @@ static noinline void __init kernel_init_freeable(void)
80492 if (!ramdisk_execute_command)
80493 ramdisk_execute_command = "/init";
80494
80495- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
80496+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
80497 ramdisk_execute_command = NULL;
80498 prepare_namespace();
80499 }
80500
80501+ grsecurity_init();
80502+
80503 /*
80504 * Ok, we have completed the initial bootup, and
80505 * we're essentially up and running. Get rid of the
80506diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
80507index 130dfec..cc88451 100644
80508--- a/ipc/ipc_sysctl.c
80509+++ b/ipc/ipc_sysctl.c
80510@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
80511 static int proc_ipc_dointvec(ctl_table *table, int write,
80512 void __user *buffer, size_t *lenp, loff_t *ppos)
80513 {
80514- struct ctl_table ipc_table;
80515+ ctl_table_no_const ipc_table;
80516
80517 memcpy(&ipc_table, table, sizeof(ipc_table));
80518 ipc_table.data = get_ipc(table);
80519@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
80520 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
80521 void __user *buffer, size_t *lenp, loff_t *ppos)
80522 {
80523- struct ctl_table ipc_table;
80524+ ctl_table_no_const ipc_table;
80525
80526 memcpy(&ipc_table, table, sizeof(ipc_table));
80527 ipc_table.data = get_ipc(table);
80528@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
80529 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
80530 void __user *buffer, size_t *lenp, loff_t *ppos)
80531 {
80532- struct ctl_table ipc_table;
80533+ ctl_table_no_const ipc_table;
80534 size_t lenp_bef = *lenp;
80535 int rc;
80536
80537@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
80538 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
80539 void __user *buffer, size_t *lenp, loff_t *ppos)
80540 {
80541- struct ctl_table ipc_table;
80542+ ctl_table_no_const ipc_table;
80543 memcpy(&ipc_table, table, sizeof(ipc_table));
80544 ipc_table.data = get_ipc(table);
80545
80546@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
80547 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
80548 void __user *buffer, size_t *lenp, loff_t *ppos)
80549 {
80550- struct ctl_table ipc_table;
80551+ ctl_table_no_const ipc_table;
80552 size_t lenp_bef = *lenp;
80553 int oldval;
80554 int rc;
80555diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
80556index 383d638..943fdbb 100644
80557--- a/ipc/mq_sysctl.c
80558+++ b/ipc/mq_sysctl.c
80559@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
80560 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
80561 void __user *buffer, size_t *lenp, loff_t *ppos)
80562 {
80563- struct ctl_table mq_table;
80564+ ctl_table_no_const mq_table;
80565 memcpy(&mq_table, table, sizeof(mq_table));
80566 mq_table.data = get_mq(table);
80567
80568diff --git a/ipc/mqueue.c b/ipc/mqueue.c
80569index e4e47f6..a85e0ad 100644
80570--- a/ipc/mqueue.c
80571+++ b/ipc/mqueue.c
80572@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
80573 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
80574 info->attr.mq_msgsize);
80575
80576+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
80577 spin_lock(&mq_lock);
80578 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
80579 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
80580diff --git a/ipc/msg.c b/ipc/msg.c
80581index d0c6d96..69a893c 100644
80582--- a/ipc/msg.c
80583+++ b/ipc/msg.c
80584@@ -296,18 +296,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
80585 return security_msg_queue_associate(msq, msgflg);
80586 }
80587
80588+static struct ipc_ops msg_ops = {
80589+ .getnew = newque,
80590+ .associate = msg_security,
80591+ .more_checks = NULL
80592+};
80593+
80594 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
80595 {
80596 struct ipc_namespace *ns;
80597- struct ipc_ops msg_ops;
80598 struct ipc_params msg_params;
80599
80600 ns = current->nsproxy->ipc_ns;
80601
80602- msg_ops.getnew = newque;
80603- msg_ops.associate = msg_security;
80604- msg_ops.more_checks = NULL;
80605-
80606 msg_params.key = key;
80607 msg_params.flg = msgflg;
80608
80609diff --git a/ipc/sem.c b/ipc/sem.c
80610index 70480a3..f4e8262 100644
80611--- a/ipc/sem.c
80612+++ b/ipc/sem.c
80613@@ -460,10 +460,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
80614 return 0;
80615 }
80616
80617+static struct ipc_ops sem_ops = {
80618+ .getnew = newary,
80619+ .associate = sem_security,
80620+ .more_checks = sem_more_checks
80621+};
80622+
80623 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80624 {
80625 struct ipc_namespace *ns;
80626- struct ipc_ops sem_ops;
80627 struct ipc_params sem_params;
80628
80629 ns = current->nsproxy->ipc_ns;
80630@@ -471,10 +476,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80631 if (nsems < 0 || nsems > ns->sc_semmsl)
80632 return -EINVAL;
80633
80634- sem_ops.getnew = newary;
80635- sem_ops.associate = sem_security;
80636- sem_ops.more_checks = sem_more_checks;
80637-
80638 sem_params.key = key;
80639 sem_params.flg = semflg;
80640 sem_params.u.nsems = nsems;
80641diff --git a/ipc/shm.c b/ipc/shm.c
80642index 7e199fa..180a1ca 100644
80643--- a/ipc/shm.c
80644+++ b/ipc/shm.c
80645@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
80646 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
80647 #endif
80648
80649+#ifdef CONFIG_GRKERNSEC
80650+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80651+ const time_t shm_createtime, const kuid_t cuid,
80652+ const int shmid);
80653+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80654+ const time_t shm_createtime);
80655+#endif
80656+
80657 void shm_init_ns(struct ipc_namespace *ns)
80658 {
80659 ns->shm_ctlmax = SHMMAX;
80660@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
80661 shp->shm_lprid = 0;
80662 shp->shm_atim = shp->shm_dtim = 0;
80663 shp->shm_ctim = get_seconds();
80664+#ifdef CONFIG_GRKERNSEC
80665+ {
80666+ struct timespec timeval;
80667+ do_posix_clock_monotonic_gettime(&timeval);
80668+
80669+ shp->shm_createtime = timeval.tv_sec;
80670+ }
80671+#endif
80672 shp->shm_segsz = size;
80673 shp->shm_nattch = 0;
80674 shp->shm_file = file;
80675@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
80676 return 0;
80677 }
80678
80679+static struct ipc_ops shm_ops = {
80680+ .getnew = newseg,
80681+ .associate = shm_security,
80682+ .more_checks = shm_more_checks
80683+};
80684+
80685 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
80686 {
80687 struct ipc_namespace *ns;
80688- struct ipc_ops shm_ops;
80689 struct ipc_params shm_params;
80690
80691 ns = current->nsproxy->ipc_ns;
80692
80693- shm_ops.getnew = newseg;
80694- shm_ops.associate = shm_security;
80695- shm_ops.more_checks = shm_more_checks;
80696-
80697 shm_params.key = key;
80698 shm_params.flg = shmflg;
80699 shm_params.u.size = size;
80700@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80701 f_mode = FMODE_READ | FMODE_WRITE;
80702 }
80703 if (shmflg & SHM_EXEC) {
80704+
80705+#ifdef CONFIG_PAX_MPROTECT
80706+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
80707+ goto out;
80708+#endif
80709+
80710 prot |= PROT_EXEC;
80711 acc_mode |= S_IXUGO;
80712 }
80713@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80714 if (err)
80715 goto out_unlock;
80716
80717+#ifdef CONFIG_GRKERNSEC
80718+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
80719+ shp->shm_perm.cuid, shmid) ||
80720+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
80721+ err = -EACCES;
80722+ goto out_unlock;
80723+ }
80724+#endif
80725+
80726 path = shp->shm_file->f_path;
80727 path_get(&path);
80728 shp->shm_nattch++;
80729+#ifdef CONFIG_GRKERNSEC
80730+ shp->shm_lapid = current->pid;
80731+#endif
80732 size = i_size_read(path.dentry->d_inode);
80733 shm_unlock(shp);
80734
80735diff --git a/kernel/acct.c b/kernel/acct.c
80736index 8d6e145..33e0b1e 100644
80737--- a/kernel/acct.c
80738+++ b/kernel/acct.c
80739@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
80740 */
80741 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
80742 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
80743- file->f_op->write(file, (char *)&ac,
80744+ file->f_op->write(file, (char __force_user *)&ac,
80745 sizeof(acct_t), &file->f_pos);
80746 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
80747 set_fs(fs);
80748diff --git a/kernel/audit.c b/kernel/audit.c
80749index 91e53d0..d9e3ec4 100644
80750--- a/kernel/audit.c
80751+++ b/kernel/audit.c
80752@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
80753 3) suppressed due to audit_rate_limit
80754 4) suppressed due to audit_backlog_limit
80755 */
80756-static atomic_t audit_lost = ATOMIC_INIT(0);
80757+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
80758
80759 /* The netlink socket. */
80760 static struct sock *audit_sock;
80761@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
80762 unsigned long now;
80763 int print;
80764
80765- atomic_inc(&audit_lost);
80766+ atomic_inc_unchecked(&audit_lost);
80767
80768 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
80769
80770@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
80771 printk(KERN_WARNING
80772 "audit: audit_lost=%d audit_rate_limit=%d "
80773 "audit_backlog_limit=%d\n",
80774- atomic_read(&audit_lost),
80775+ atomic_read_unchecked(&audit_lost),
80776 audit_rate_limit,
80777 audit_backlog_limit);
80778 audit_panic(message);
80779@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80780 status_set.pid = audit_pid;
80781 status_set.rate_limit = audit_rate_limit;
80782 status_set.backlog_limit = audit_backlog_limit;
80783- status_set.lost = atomic_read(&audit_lost);
80784+ status_set.lost = atomic_read_unchecked(&audit_lost);
80785 status_set.backlog = skb_queue_len(&audit_skb_queue);
80786 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
80787 &status_set, sizeof(status_set));
80788diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
80789index 6bd4a90..0ee9eff 100644
80790--- a/kernel/auditfilter.c
80791+++ b/kernel/auditfilter.c
80792@@ -423,7 +423,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
80793 f->lsm_rule = NULL;
80794
80795 /* Support legacy tests for a valid loginuid */
80796- if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295)) {
80797+ if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295U)) {
80798 f->type = AUDIT_LOGINUID_SET;
80799 f->val = 0;
80800 }
80801diff --git a/kernel/auditsc.c b/kernel/auditsc.c
80802index 3c8a601..3a416f6 100644
80803--- a/kernel/auditsc.c
80804+++ b/kernel/auditsc.c
80805@@ -1956,7 +1956,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
80806 }
80807
80808 /* global counter which is incremented every time something logs in */
80809-static atomic_t session_id = ATOMIC_INIT(0);
80810+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
80811
80812 /**
80813 * audit_set_loginuid - set current task's audit_context loginuid
80814@@ -1980,7 +1980,7 @@ int audit_set_loginuid(kuid_t loginuid)
80815 return -EPERM;
80816 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
80817
80818- sessionid = atomic_inc_return(&session_id);
80819+ sessionid = atomic_inc_return_unchecked(&session_id);
80820 if (context && context->in_syscall) {
80821 struct audit_buffer *ab;
80822
80823diff --git a/kernel/capability.c b/kernel/capability.c
80824index f6c2ce5..982c0f9 100644
80825--- a/kernel/capability.c
80826+++ b/kernel/capability.c
80827@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
80828 * before modification is attempted and the application
80829 * fails.
80830 */
80831+ if (tocopy > ARRAY_SIZE(kdata))
80832+ return -EFAULT;
80833+
80834 if (copy_to_user(dataptr, kdata, tocopy
80835 * sizeof(struct __user_cap_data_struct))) {
80836 return -EFAULT;
80837@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
80838 int ret;
80839
80840 rcu_read_lock();
80841- ret = security_capable(__task_cred(t), ns, cap);
80842+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
80843+ gr_task_is_capable(t, __task_cred(t), cap);
80844 rcu_read_unlock();
80845
80846- return (ret == 0);
80847+ return ret;
80848 }
80849
80850 /**
80851@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
80852 int ret;
80853
80854 rcu_read_lock();
80855- ret = security_capable_noaudit(__task_cred(t), ns, cap);
80856+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
80857 rcu_read_unlock();
80858
80859- return (ret == 0);
80860+ return ret;
80861 }
80862
80863 /**
80864@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
80865 BUG();
80866 }
80867
80868- if (security_capable(current_cred(), ns, cap) == 0) {
80869+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
80870 current->flags |= PF_SUPERPRIV;
80871 return true;
80872 }
80873@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
80874 }
80875 EXPORT_SYMBOL(ns_capable);
80876
80877+bool ns_capable_nolog(struct user_namespace *ns, int cap)
80878+{
80879+ if (unlikely(!cap_valid(cap))) {
80880+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
80881+ BUG();
80882+ }
80883+
80884+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
80885+ current->flags |= PF_SUPERPRIV;
80886+ return true;
80887+ }
80888+ return false;
80889+}
80890+EXPORT_SYMBOL(ns_capable_nolog);
80891+
80892 /**
80893 * file_ns_capable - Determine if the file's opener had a capability in effect
80894 * @file: The file we want to check
80895@@ -432,6 +451,12 @@ bool capable(int cap)
80896 }
80897 EXPORT_SYMBOL(capable);
80898
80899+bool capable_nolog(int cap)
80900+{
80901+ return ns_capable_nolog(&init_user_ns, cap);
80902+}
80903+EXPORT_SYMBOL(capable_nolog);
80904+
80905 /**
80906 * nsown_capable - Check superior capability to one's own user_ns
80907 * @cap: The capability in question
80908@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
80909
80910 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80911 }
80912+
80913+bool inode_capable_nolog(const struct inode *inode, int cap)
80914+{
80915+ struct user_namespace *ns = current_user_ns();
80916+
80917+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80918+}
80919diff --git a/kernel/cgroup.c b/kernel/cgroup.c
80920index 2e9b387..61817b1 100644
80921--- a/kernel/cgroup.c
80922+++ b/kernel/cgroup.c
80923@@ -5398,7 +5398,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
80924 struct css_set *cg = link->cg;
80925 struct task_struct *task;
80926 int count = 0;
80927- seq_printf(seq, "css_set %p\n", cg);
80928+ seq_printf(seq, "css_set %pK\n", cg);
80929 list_for_each_entry(task, &cg->tasks, cg_list) {
80930 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
80931 seq_puts(seq, " ...\n");
80932diff --git a/kernel/compat.c b/kernel/compat.c
80933index 0a09e48..f44f3f0 100644
80934--- a/kernel/compat.c
80935+++ b/kernel/compat.c
80936@@ -13,6 +13,7 @@
80937
80938 #include <linux/linkage.h>
80939 #include <linux/compat.h>
80940+#include <linux/module.h>
80941 #include <linux/errno.h>
80942 #include <linux/time.h>
80943 #include <linux/signal.h>
80944@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
80945 mm_segment_t oldfs;
80946 long ret;
80947
80948- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
80949+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
80950 oldfs = get_fs();
80951 set_fs(KERNEL_DS);
80952 ret = hrtimer_nanosleep_restart(restart);
80953@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
80954 oldfs = get_fs();
80955 set_fs(KERNEL_DS);
80956 ret = hrtimer_nanosleep(&tu,
80957- rmtp ? (struct timespec __user *)&rmt : NULL,
80958+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
80959 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
80960 set_fs(oldfs);
80961
80962@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
80963 mm_segment_t old_fs = get_fs();
80964
80965 set_fs(KERNEL_DS);
80966- ret = sys_sigpending((old_sigset_t __user *) &s);
80967+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
80968 set_fs(old_fs);
80969 if (ret == 0)
80970 ret = put_user(s, set);
80971@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
80972 mm_segment_t old_fs = get_fs();
80973
80974 set_fs(KERNEL_DS);
80975- ret = sys_old_getrlimit(resource, &r);
80976+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
80977 set_fs(old_fs);
80978
80979 if (!ret) {
80980@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
80981 set_fs (KERNEL_DS);
80982 ret = sys_wait4(pid,
80983 (stat_addr ?
80984- (unsigned int __user *) &status : NULL),
80985- options, (struct rusage __user *) &r);
80986+ (unsigned int __force_user *) &status : NULL),
80987+ options, (struct rusage __force_user *) &r);
80988 set_fs (old_fs);
80989
80990 if (ret > 0) {
80991@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
80992 memset(&info, 0, sizeof(info));
80993
80994 set_fs(KERNEL_DS);
80995- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
80996- uru ? (struct rusage __user *)&ru : NULL);
80997+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
80998+ uru ? (struct rusage __force_user *)&ru : NULL);
80999 set_fs(old_fs);
81000
81001 if ((ret < 0) || (info.si_signo == 0))
81002@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
81003 oldfs = get_fs();
81004 set_fs(KERNEL_DS);
81005 err = sys_timer_settime(timer_id, flags,
81006- (struct itimerspec __user *) &newts,
81007- (struct itimerspec __user *) &oldts);
81008+ (struct itimerspec __force_user *) &newts,
81009+ (struct itimerspec __force_user *) &oldts);
81010 set_fs(oldfs);
81011 if (!err && old && put_compat_itimerspec(old, &oldts))
81012 return -EFAULT;
81013@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
81014 oldfs = get_fs();
81015 set_fs(KERNEL_DS);
81016 err = sys_timer_gettime(timer_id,
81017- (struct itimerspec __user *) &ts);
81018+ (struct itimerspec __force_user *) &ts);
81019 set_fs(oldfs);
81020 if (!err && put_compat_itimerspec(setting, &ts))
81021 return -EFAULT;
81022@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
81023 oldfs = get_fs();
81024 set_fs(KERNEL_DS);
81025 err = sys_clock_settime(which_clock,
81026- (struct timespec __user *) &ts);
81027+ (struct timespec __force_user *) &ts);
81028 set_fs(oldfs);
81029 return err;
81030 }
81031@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
81032 oldfs = get_fs();
81033 set_fs(KERNEL_DS);
81034 err = sys_clock_gettime(which_clock,
81035- (struct timespec __user *) &ts);
81036+ (struct timespec __force_user *) &ts);
81037 set_fs(oldfs);
81038 if (!err && put_compat_timespec(&ts, tp))
81039 return -EFAULT;
81040@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
81041
81042 oldfs = get_fs();
81043 set_fs(KERNEL_DS);
81044- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
81045+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
81046 set_fs(oldfs);
81047
81048 err = compat_put_timex(utp, &txc);
81049@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
81050 oldfs = get_fs();
81051 set_fs(KERNEL_DS);
81052 err = sys_clock_getres(which_clock,
81053- (struct timespec __user *) &ts);
81054+ (struct timespec __force_user *) &ts);
81055 set_fs(oldfs);
81056 if (!err && tp && put_compat_timespec(&ts, tp))
81057 return -EFAULT;
81058@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
81059 long err;
81060 mm_segment_t oldfs;
81061 struct timespec tu;
81062- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
81063+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
81064
81065- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
81066+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
81067 oldfs = get_fs();
81068 set_fs(KERNEL_DS);
81069 err = clock_nanosleep_restart(restart);
81070@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
81071 oldfs = get_fs();
81072 set_fs(KERNEL_DS);
81073 err = sys_clock_nanosleep(which_clock, flags,
81074- (struct timespec __user *) &in,
81075- (struct timespec __user *) &out);
81076+ (struct timespec __force_user *) &in,
81077+ (struct timespec __force_user *) &out);
81078 set_fs(oldfs);
81079
81080 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
81081diff --git a/kernel/configs.c b/kernel/configs.c
81082index c18b1f1..b9a0132 100644
81083--- a/kernel/configs.c
81084+++ b/kernel/configs.c
81085@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
81086 struct proc_dir_entry *entry;
81087
81088 /* create the current config file */
81089+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
81090+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
81091+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
81092+ &ikconfig_file_ops);
81093+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81094+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
81095+ &ikconfig_file_ops);
81096+#endif
81097+#else
81098 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
81099 &ikconfig_file_ops);
81100+#endif
81101+
81102 if (!entry)
81103 return -ENOMEM;
81104
81105diff --git a/kernel/cred.c b/kernel/cred.c
81106index e0573a4..3874e41 100644
81107--- a/kernel/cred.c
81108+++ b/kernel/cred.c
81109@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
81110 validate_creds(cred);
81111 alter_cred_subscribers(cred, -1);
81112 put_cred(cred);
81113+
81114+#ifdef CONFIG_GRKERNSEC_SETXID
81115+ cred = (struct cred *) tsk->delayed_cred;
81116+ if (cred != NULL) {
81117+ tsk->delayed_cred = NULL;
81118+ validate_creds(cred);
81119+ alter_cred_subscribers(cred, -1);
81120+ put_cred(cred);
81121+ }
81122+#endif
81123 }
81124
81125 /**
81126@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
81127 * Always returns 0 thus allowing this function to be tail-called at the end
81128 * of, say, sys_setgid().
81129 */
81130-int commit_creds(struct cred *new)
81131+static int __commit_creds(struct cred *new)
81132 {
81133 struct task_struct *task = current;
81134 const struct cred *old = task->real_cred;
81135@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
81136
81137 get_cred(new); /* we will require a ref for the subj creds too */
81138
81139+ gr_set_role_label(task, new->uid, new->gid);
81140+
81141 /* dumpability changes */
81142 if (!uid_eq(old->euid, new->euid) ||
81143 !gid_eq(old->egid, new->egid) ||
81144@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
81145 put_cred(old);
81146 return 0;
81147 }
81148+#ifdef CONFIG_GRKERNSEC_SETXID
81149+extern int set_user(struct cred *new);
81150+
81151+void gr_delayed_cred_worker(void)
81152+{
81153+ const struct cred *new = current->delayed_cred;
81154+ struct cred *ncred;
81155+
81156+ current->delayed_cred = NULL;
81157+
81158+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
81159+ // from doing get_cred on it when queueing this
81160+ put_cred(new);
81161+ return;
81162+ } else if (new == NULL)
81163+ return;
81164+
81165+ ncred = prepare_creds();
81166+ if (!ncred)
81167+ goto die;
81168+ // uids
81169+ ncred->uid = new->uid;
81170+ ncred->euid = new->euid;
81171+ ncred->suid = new->suid;
81172+ ncred->fsuid = new->fsuid;
81173+ // gids
81174+ ncred->gid = new->gid;
81175+ ncred->egid = new->egid;
81176+ ncred->sgid = new->sgid;
81177+ ncred->fsgid = new->fsgid;
81178+ // groups
81179+ if (set_groups(ncred, new->group_info) < 0) {
81180+ abort_creds(ncred);
81181+ goto die;
81182+ }
81183+ // caps
81184+ ncred->securebits = new->securebits;
81185+ ncred->cap_inheritable = new->cap_inheritable;
81186+ ncred->cap_permitted = new->cap_permitted;
81187+ ncred->cap_effective = new->cap_effective;
81188+ ncred->cap_bset = new->cap_bset;
81189+
81190+ if (set_user(ncred)) {
81191+ abort_creds(ncred);
81192+ goto die;
81193+ }
81194+
81195+ // from doing get_cred on it when queueing this
81196+ put_cred(new);
81197+
81198+ __commit_creds(ncred);
81199+ return;
81200+die:
81201+ // from doing get_cred on it when queueing this
81202+ put_cred(new);
81203+ do_group_exit(SIGKILL);
81204+}
81205+#endif
81206+
81207+int commit_creds(struct cred *new)
81208+{
81209+#ifdef CONFIG_GRKERNSEC_SETXID
81210+ int ret;
81211+ int schedule_it = 0;
81212+ struct task_struct *t;
81213+
81214+ /* we won't get called with tasklist_lock held for writing
81215+ and interrupts disabled as the cred struct in that case is
81216+ init_cred
81217+ */
81218+ if (grsec_enable_setxid && !current_is_single_threaded() &&
81219+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
81220+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
81221+ schedule_it = 1;
81222+ }
81223+ ret = __commit_creds(new);
81224+ if (schedule_it) {
81225+ rcu_read_lock();
81226+ read_lock(&tasklist_lock);
81227+ for (t = next_thread(current); t != current;
81228+ t = next_thread(t)) {
81229+ if (t->delayed_cred == NULL) {
81230+ t->delayed_cred = get_cred(new);
81231+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
81232+ set_tsk_need_resched(t);
81233+ }
81234+ }
81235+ read_unlock(&tasklist_lock);
81236+ rcu_read_unlock();
81237+ }
81238+ return ret;
81239+#else
81240+ return __commit_creds(new);
81241+#endif
81242+}
81243+
81244 EXPORT_SYMBOL(commit_creds);
81245
81246 /**
81247diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
81248index 0506d44..2c20034 100644
81249--- a/kernel/debug/debug_core.c
81250+++ b/kernel/debug/debug_core.c
81251@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
81252 */
81253 static atomic_t masters_in_kgdb;
81254 static atomic_t slaves_in_kgdb;
81255-static atomic_t kgdb_break_tasklet_var;
81256+static atomic_unchecked_t kgdb_break_tasklet_var;
81257 atomic_t kgdb_setting_breakpoint;
81258
81259 struct task_struct *kgdb_usethread;
81260@@ -133,7 +133,7 @@ int kgdb_single_step;
81261 static pid_t kgdb_sstep_pid;
81262
81263 /* to keep track of the CPU which is doing the single stepping*/
81264-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81265+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81266
81267 /*
81268 * If you are debugging a problem where roundup (the collection of
81269@@ -541,7 +541,7 @@ return_normal:
81270 * kernel will only try for the value of sstep_tries before
81271 * giving up and continuing on.
81272 */
81273- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
81274+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
81275 (kgdb_info[cpu].task &&
81276 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
81277 atomic_set(&kgdb_active, -1);
81278@@ -635,8 +635,8 @@ cpu_master_loop:
81279 }
81280
81281 kgdb_restore:
81282- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
81283- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
81284+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
81285+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
81286 if (kgdb_info[sstep_cpu].task)
81287 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
81288 else
81289@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
81290 static void kgdb_tasklet_bpt(unsigned long ing)
81291 {
81292 kgdb_breakpoint();
81293- atomic_set(&kgdb_break_tasklet_var, 0);
81294+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
81295 }
81296
81297 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
81298
81299 void kgdb_schedule_breakpoint(void)
81300 {
81301- if (atomic_read(&kgdb_break_tasklet_var) ||
81302+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
81303 atomic_read(&kgdb_active) != -1 ||
81304 atomic_read(&kgdb_setting_breakpoint))
81305 return;
81306- atomic_inc(&kgdb_break_tasklet_var);
81307+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
81308 tasklet_schedule(&kgdb_tasklet_breakpoint);
81309 }
81310 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
81311diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
81312index 00eb8f7..d7e3244 100644
81313--- a/kernel/debug/kdb/kdb_main.c
81314+++ b/kernel/debug/kdb/kdb_main.c
81315@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
81316 continue;
81317
81318 kdb_printf("%-20s%8u 0x%p ", mod->name,
81319- mod->core_size, (void *)mod);
81320+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
81321 #ifdef CONFIG_MODULE_UNLOAD
81322 kdb_printf("%4ld ", module_refcount(mod));
81323 #endif
81324@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
81325 kdb_printf(" (Loading)");
81326 else
81327 kdb_printf(" (Live)");
81328- kdb_printf(" 0x%p", mod->module_core);
81329+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
81330
81331 #ifdef CONFIG_MODULE_UNLOAD
81332 {
81333diff --git a/kernel/events/core.c b/kernel/events/core.c
81334index e76e495..cbfe63a 100644
81335--- a/kernel/events/core.c
81336+++ b/kernel/events/core.c
81337@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
81338 * 0 - disallow raw tracepoint access for unpriv
81339 * 1 - disallow cpu events for unpriv
81340 * 2 - disallow kernel profiling for unpriv
81341+ * 3 - disallow all unpriv perf event use
81342 */
81343-int sysctl_perf_event_paranoid __read_mostly = 1;
81344+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81345+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
81346+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
81347+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
81348+#else
81349+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
81350+#endif
81351
81352 /* Minimum for 512 kiB + 1 user control page */
81353 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
81354@@ -184,7 +191,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
81355 return 0;
81356 }
81357
81358-static atomic64_t perf_event_id;
81359+static atomic64_unchecked_t perf_event_id;
81360
81361 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
81362 enum event_type_t event_type);
81363@@ -2747,7 +2754,7 @@ static void __perf_event_read(void *info)
81364
81365 static inline u64 perf_event_count(struct perf_event *event)
81366 {
81367- return local64_read(&event->count) + atomic64_read(&event->child_count);
81368+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
81369 }
81370
81371 static u64 perf_event_read(struct perf_event *event)
81372@@ -3093,9 +3100,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
81373 mutex_lock(&event->child_mutex);
81374 total += perf_event_read(event);
81375 *enabled += event->total_time_enabled +
81376- atomic64_read(&event->child_total_time_enabled);
81377+ atomic64_read_unchecked(&event->child_total_time_enabled);
81378 *running += event->total_time_running +
81379- atomic64_read(&event->child_total_time_running);
81380+ atomic64_read_unchecked(&event->child_total_time_running);
81381
81382 list_for_each_entry(child, &event->child_list, child_list) {
81383 total += perf_event_read(child);
81384@@ -3481,10 +3488,10 @@ void perf_event_update_userpage(struct perf_event *event)
81385 userpg->offset -= local64_read(&event->hw.prev_count);
81386
81387 userpg->time_enabled = enabled +
81388- atomic64_read(&event->child_total_time_enabled);
81389+ atomic64_read_unchecked(&event->child_total_time_enabled);
81390
81391 userpg->time_running = running +
81392- atomic64_read(&event->child_total_time_running);
81393+ atomic64_read_unchecked(&event->child_total_time_running);
81394
81395 arch_perf_update_userpage(userpg, now);
81396
81397@@ -4034,7 +4041,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
81398
81399 /* Data. */
81400 sp = perf_user_stack_pointer(regs);
81401- rem = __output_copy_user(handle, (void *) sp, dump_size);
81402+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
81403 dyn_size = dump_size - rem;
81404
81405 perf_output_skip(handle, rem);
81406@@ -4122,11 +4129,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
81407 values[n++] = perf_event_count(event);
81408 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
81409 values[n++] = enabled +
81410- atomic64_read(&event->child_total_time_enabled);
81411+ atomic64_read_unchecked(&event->child_total_time_enabled);
81412 }
81413 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
81414 values[n++] = running +
81415- atomic64_read(&event->child_total_time_running);
81416+ atomic64_read_unchecked(&event->child_total_time_running);
81417 }
81418 if (read_format & PERF_FORMAT_ID)
81419 values[n++] = primary_event_id(event);
81420@@ -4835,12 +4842,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
81421 * need to add enough zero bytes after the string to handle
81422 * the 64bit alignment we do later.
81423 */
81424- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
81425+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
81426 if (!buf) {
81427 name = strncpy(tmp, "//enomem", sizeof(tmp));
81428 goto got_name;
81429 }
81430- name = d_path(&file->f_path, buf, PATH_MAX);
81431+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
81432 if (IS_ERR(name)) {
81433 name = strncpy(tmp, "//toolong", sizeof(tmp));
81434 goto got_name;
81435@@ -6262,7 +6269,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
81436 event->parent = parent_event;
81437
81438 event->ns = get_pid_ns(task_active_pid_ns(current));
81439- event->id = atomic64_inc_return(&perf_event_id);
81440+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
81441
81442 event->state = PERF_EVENT_STATE_INACTIVE;
81443
81444@@ -6572,6 +6579,11 @@ SYSCALL_DEFINE5(perf_event_open,
81445 if (flags & ~PERF_FLAG_ALL)
81446 return -EINVAL;
81447
81448+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81449+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
81450+ return -EACCES;
81451+#endif
81452+
81453 err = perf_copy_attr(attr_uptr, &attr);
81454 if (err)
81455 return err;
81456@@ -6904,10 +6916,10 @@ static void sync_child_event(struct perf_event *child_event,
81457 /*
81458 * Add back the child's count to the parent's count:
81459 */
81460- atomic64_add(child_val, &parent_event->child_count);
81461- atomic64_add(child_event->total_time_enabled,
81462+ atomic64_add_unchecked(child_val, &parent_event->child_count);
81463+ atomic64_add_unchecked(child_event->total_time_enabled,
81464 &parent_event->child_total_time_enabled);
81465- atomic64_add(child_event->total_time_running,
81466+ atomic64_add_unchecked(child_event->total_time_running,
81467 &parent_event->child_total_time_running);
81468
81469 /*
81470diff --git a/kernel/events/internal.h b/kernel/events/internal.h
81471index ca65997..60df03d 100644
81472--- a/kernel/events/internal.h
81473+++ b/kernel/events/internal.h
81474@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
81475 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
81476 }
81477
81478-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
81479-static inline unsigned int \
81480+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
81481+static inline unsigned long \
81482 func_name(struct perf_output_handle *handle, \
81483- const void *buf, unsigned int len) \
81484+ const void user *buf, unsigned long len) \
81485 { \
81486 unsigned long size, written; \
81487 \
81488@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
81489 return n;
81490 }
81491
81492-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
81493+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
81494
81495 #define MEMCPY_SKIP(dst, src, n) (n)
81496
81497-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
81498+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
81499
81500 #ifndef arch_perf_out_copy_user
81501 #define arch_perf_out_copy_user __copy_from_user_inatomic
81502 #endif
81503
81504-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
81505+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
81506
81507 /* Callchain handling */
81508 extern struct perf_callchain_entry *
81509diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
81510index f356974..cb8c570 100644
81511--- a/kernel/events/uprobes.c
81512+++ b/kernel/events/uprobes.c
81513@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
81514 {
81515 struct page *page;
81516 uprobe_opcode_t opcode;
81517- int result;
81518+ long result;
81519
81520 pagefault_disable();
81521 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
81522diff --git a/kernel/exit.c b/kernel/exit.c
81523index 7bb73f9..d7978ed 100644
81524--- a/kernel/exit.c
81525+++ b/kernel/exit.c
81526@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
81527 struct task_struct *leader;
81528 int zap_leader;
81529 repeat:
81530+#ifdef CONFIG_NET
81531+ gr_del_task_from_ip_table(p);
81532+#endif
81533+
81534 /* don't need to get the RCU readlock here - the process is dead and
81535 * can't be modifying its own credentials. But shut RCU-lockdep up */
81536 rcu_read_lock();
81537@@ -340,7 +344,7 @@ int allow_signal(int sig)
81538 * know it'll be handled, so that they don't get converted to
81539 * SIGKILL or just silently dropped.
81540 */
81541- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
81542+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
81543 recalc_sigpending();
81544 spin_unlock_irq(&current->sighand->siglock);
81545 return 0;
81546@@ -709,6 +713,8 @@ void do_exit(long code)
81547 struct task_struct *tsk = current;
81548 int group_dead;
81549
81550+ set_fs(USER_DS);
81551+
81552 profile_task_exit(tsk);
81553
81554 WARN_ON(blk_needs_flush_plug(tsk));
81555@@ -725,7 +731,6 @@ void do_exit(long code)
81556 * mm_release()->clear_child_tid() from writing to a user-controlled
81557 * kernel address.
81558 */
81559- set_fs(USER_DS);
81560
81561 ptrace_event(PTRACE_EVENT_EXIT, code);
81562
81563@@ -784,6 +789,9 @@ void do_exit(long code)
81564 tsk->exit_code = code;
81565 taskstats_exit(tsk, group_dead);
81566
81567+ gr_acl_handle_psacct(tsk, code);
81568+ gr_acl_handle_exit();
81569+
81570 exit_mm(tsk);
81571
81572 if (group_dead)
81573@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
81574 * Take down every thread in the group. This is called by fatal signals
81575 * as well as by sys_exit_group (below).
81576 */
81577-void
81578+__noreturn void
81579 do_group_exit(int exit_code)
81580 {
81581 struct signal_struct *sig = current->signal;
81582diff --git a/kernel/fork.c b/kernel/fork.c
81583index ffbc090..08ceeee 100644
81584--- a/kernel/fork.c
81585+++ b/kernel/fork.c
81586@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
81587 *stackend = STACK_END_MAGIC; /* for overflow detection */
81588
81589 #ifdef CONFIG_CC_STACKPROTECTOR
81590- tsk->stack_canary = get_random_int();
81591+ tsk->stack_canary = pax_get_random_long();
81592 #endif
81593
81594 /*
81595@@ -345,13 +345,81 @@ free_tsk:
81596 }
81597
81598 #ifdef CONFIG_MMU
81599+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
81600+{
81601+ struct vm_area_struct *tmp;
81602+ unsigned long charge;
81603+ struct mempolicy *pol;
81604+ struct file *file;
81605+
81606+ charge = 0;
81607+ if (mpnt->vm_flags & VM_ACCOUNT) {
81608+ unsigned long len = vma_pages(mpnt);
81609+
81610+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81611+ goto fail_nomem;
81612+ charge = len;
81613+ }
81614+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81615+ if (!tmp)
81616+ goto fail_nomem;
81617+ *tmp = *mpnt;
81618+ tmp->vm_mm = mm;
81619+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
81620+ pol = mpol_dup(vma_policy(mpnt));
81621+ if (IS_ERR(pol))
81622+ goto fail_nomem_policy;
81623+ vma_set_policy(tmp, pol);
81624+ if (anon_vma_fork(tmp, mpnt))
81625+ goto fail_nomem_anon_vma_fork;
81626+ tmp->vm_flags &= ~VM_LOCKED;
81627+ tmp->vm_next = tmp->vm_prev = NULL;
81628+ tmp->vm_mirror = NULL;
81629+ file = tmp->vm_file;
81630+ if (file) {
81631+ struct inode *inode = file_inode(file);
81632+ struct address_space *mapping = file->f_mapping;
81633+
81634+ get_file(file);
81635+ if (tmp->vm_flags & VM_DENYWRITE)
81636+ atomic_dec(&inode->i_writecount);
81637+ mutex_lock(&mapping->i_mmap_mutex);
81638+ if (tmp->vm_flags & VM_SHARED)
81639+ mapping->i_mmap_writable++;
81640+ flush_dcache_mmap_lock(mapping);
81641+ /* insert tmp into the share list, just after mpnt */
81642+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81643+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
81644+ else
81645+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
81646+ flush_dcache_mmap_unlock(mapping);
81647+ mutex_unlock(&mapping->i_mmap_mutex);
81648+ }
81649+
81650+ /*
81651+ * Clear hugetlb-related page reserves for children. This only
81652+ * affects MAP_PRIVATE mappings. Faults generated by the child
81653+ * are not guaranteed to succeed, even if read-only
81654+ */
81655+ if (is_vm_hugetlb_page(tmp))
81656+ reset_vma_resv_huge_pages(tmp);
81657+
81658+ return tmp;
81659+
81660+fail_nomem_anon_vma_fork:
81661+ mpol_put(pol);
81662+fail_nomem_policy:
81663+ kmem_cache_free(vm_area_cachep, tmp);
81664+fail_nomem:
81665+ vm_unacct_memory(charge);
81666+ return NULL;
81667+}
81668+
81669 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81670 {
81671 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
81672 struct rb_node **rb_link, *rb_parent;
81673 int retval;
81674- unsigned long charge;
81675- struct mempolicy *pol;
81676
81677 uprobe_start_dup_mmap();
81678 down_write(&oldmm->mmap_sem);
81679@@ -365,8 +433,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81680 mm->locked_vm = 0;
81681 mm->mmap = NULL;
81682 mm->mmap_cache = NULL;
81683- mm->free_area_cache = oldmm->mmap_base;
81684- mm->cached_hole_size = ~0UL;
81685+ mm->free_area_cache = oldmm->free_area_cache;
81686+ mm->cached_hole_size = oldmm->cached_hole_size;
81687 mm->map_count = 0;
81688 cpumask_clear(mm_cpumask(mm));
81689 mm->mm_rb = RB_ROOT;
81690@@ -382,57 +450,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81691
81692 prev = NULL;
81693 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
81694- struct file *file;
81695-
81696 if (mpnt->vm_flags & VM_DONTCOPY) {
81697 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
81698 -vma_pages(mpnt));
81699 continue;
81700 }
81701- charge = 0;
81702- if (mpnt->vm_flags & VM_ACCOUNT) {
81703- unsigned long len = vma_pages(mpnt);
81704-
81705- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81706- goto fail_nomem;
81707- charge = len;
81708- }
81709- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81710- if (!tmp)
81711- goto fail_nomem;
81712- *tmp = *mpnt;
81713- INIT_LIST_HEAD(&tmp->anon_vma_chain);
81714- pol = mpol_dup(vma_policy(mpnt));
81715- retval = PTR_ERR(pol);
81716- if (IS_ERR(pol))
81717- goto fail_nomem_policy;
81718- vma_set_policy(tmp, pol);
81719- tmp->vm_mm = mm;
81720- if (anon_vma_fork(tmp, mpnt))
81721- goto fail_nomem_anon_vma_fork;
81722- tmp->vm_flags &= ~VM_LOCKED;
81723- tmp->vm_next = tmp->vm_prev = NULL;
81724- file = tmp->vm_file;
81725- if (file) {
81726- struct inode *inode = file_inode(file);
81727- struct address_space *mapping = file->f_mapping;
81728-
81729- get_file(file);
81730- if (tmp->vm_flags & VM_DENYWRITE)
81731- atomic_dec(&inode->i_writecount);
81732- mutex_lock(&mapping->i_mmap_mutex);
81733- if (tmp->vm_flags & VM_SHARED)
81734- mapping->i_mmap_writable++;
81735- flush_dcache_mmap_lock(mapping);
81736- /* insert tmp into the share list, just after mpnt */
81737- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81738- vma_nonlinear_insert(tmp,
81739- &mapping->i_mmap_nonlinear);
81740- else
81741- vma_interval_tree_insert_after(tmp, mpnt,
81742- &mapping->i_mmap);
81743- flush_dcache_mmap_unlock(mapping);
81744- mutex_unlock(&mapping->i_mmap_mutex);
81745+ tmp = dup_vma(mm, oldmm, mpnt);
81746+ if (!tmp) {
81747+ retval = -ENOMEM;
81748+ goto out;
81749 }
81750
81751 /*
81752@@ -464,6 +490,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81753 if (retval)
81754 goto out;
81755 }
81756+
81757+#ifdef CONFIG_PAX_SEGMEXEC
81758+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
81759+ struct vm_area_struct *mpnt_m;
81760+
81761+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
81762+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
81763+
81764+ if (!mpnt->vm_mirror)
81765+ continue;
81766+
81767+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
81768+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
81769+ mpnt->vm_mirror = mpnt_m;
81770+ } else {
81771+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
81772+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
81773+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
81774+ mpnt->vm_mirror->vm_mirror = mpnt;
81775+ }
81776+ }
81777+ BUG_ON(mpnt_m);
81778+ }
81779+#endif
81780+
81781 /* a new mm has just been created */
81782 arch_dup_mmap(oldmm, mm);
81783 retval = 0;
81784@@ -473,14 +524,6 @@ out:
81785 up_write(&oldmm->mmap_sem);
81786 uprobe_end_dup_mmap();
81787 return retval;
81788-fail_nomem_anon_vma_fork:
81789- mpol_put(pol);
81790-fail_nomem_policy:
81791- kmem_cache_free(vm_area_cachep, tmp);
81792-fail_nomem:
81793- retval = -ENOMEM;
81794- vm_unacct_memory(charge);
81795- goto out;
81796 }
81797
81798 static inline int mm_alloc_pgd(struct mm_struct *mm)
81799@@ -695,8 +738,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
81800 return ERR_PTR(err);
81801
81802 mm = get_task_mm(task);
81803- if (mm && mm != current->mm &&
81804- !ptrace_may_access(task, mode)) {
81805+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
81806+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
81807 mmput(mm);
81808 mm = ERR_PTR(-EACCES);
81809 }
81810@@ -918,13 +961,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
81811 spin_unlock(&fs->lock);
81812 return -EAGAIN;
81813 }
81814- fs->users++;
81815+ atomic_inc(&fs->users);
81816 spin_unlock(&fs->lock);
81817 return 0;
81818 }
81819 tsk->fs = copy_fs_struct(fs);
81820 if (!tsk->fs)
81821 return -ENOMEM;
81822+ /* Carry through gr_chroot_dentry and is_chrooted instead
81823+ of recomputing it here. Already copied when the task struct
81824+ is duplicated. This allows pivot_root to not be treated as
81825+ a chroot
81826+ */
81827+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
81828+
81829 return 0;
81830 }
81831
81832@@ -1197,10 +1247,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81833 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
81834 #endif
81835 retval = -EAGAIN;
81836+
81837+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
81838+
81839 if (atomic_read(&p->real_cred->user->processes) >=
81840 task_rlimit(p, RLIMIT_NPROC)) {
81841- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
81842- p->real_cred->user != INIT_USER)
81843+ if (p->real_cred->user != INIT_USER &&
81844+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
81845 goto bad_fork_free;
81846 }
81847 current->flags &= ~PF_NPROC_EXCEEDED;
81848@@ -1446,6 +1499,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81849 goto bad_fork_free_pid;
81850 }
81851
81852+ /* synchronizes with gr_set_acls()
81853+ we need to call this past the point of no return for fork()
81854+ */
81855+ gr_copy_label(p);
81856+
81857 if (clone_flags & CLONE_THREAD) {
81858 current->signal->nr_threads++;
81859 atomic_inc(&current->signal->live);
81860@@ -1529,6 +1587,8 @@ bad_fork_cleanup_count:
81861 bad_fork_free:
81862 free_task(p);
81863 fork_out:
81864+ gr_log_forkfail(retval);
81865+
81866 return ERR_PTR(retval);
81867 }
81868
81869@@ -1613,6 +1673,8 @@ long do_fork(unsigned long clone_flags,
81870 if (clone_flags & CLONE_PARENT_SETTID)
81871 put_user(nr, parent_tidptr);
81872
81873+ gr_handle_brute_check();
81874+
81875 if (clone_flags & CLONE_VFORK) {
81876 p->vfork_done = &vfork;
81877 init_completion(&vfork);
81878@@ -1729,7 +1791,7 @@ void __init proc_caches_init(void)
81879 mm_cachep = kmem_cache_create("mm_struct",
81880 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
81881 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
81882- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
81883+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
81884 mmap_init();
81885 nsproxy_cache_init();
81886 }
81887@@ -1769,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
81888 return 0;
81889
81890 /* don't need lock here; in the worst case we'll do useless copy */
81891- if (fs->users == 1)
81892+ if (atomic_read(&fs->users) == 1)
81893 return 0;
81894
81895 *new_fsp = copy_fs_struct(fs);
81896@@ -1881,7 +1943,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
81897 fs = current->fs;
81898 spin_lock(&fs->lock);
81899 current->fs = new_fs;
81900- if (--fs->users)
81901+ gr_set_chroot_entries(current, &current->fs->root);
81902+ if (atomic_dec_return(&fs->users))
81903 new_fs = NULL;
81904 else
81905 new_fs = fs;
81906diff --git a/kernel/futex.c b/kernel/futex.c
81907index 49dacfb..2ac4526 100644
81908--- a/kernel/futex.c
81909+++ b/kernel/futex.c
81910@@ -54,6 +54,7 @@
81911 #include <linux/mount.h>
81912 #include <linux/pagemap.h>
81913 #include <linux/syscalls.h>
81914+#include <linux/ptrace.h>
81915 #include <linux/signal.h>
81916 #include <linux/export.h>
81917 #include <linux/magic.h>
81918@@ -242,6 +243,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
81919 struct page *page, *page_head;
81920 int err, ro = 0;
81921
81922+#ifdef CONFIG_PAX_SEGMEXEC
81923+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
81924+ return -EFAULT;
81925+#endif
81926+
81927 /*
81928 * The futex address must be "naturally" aligned.
81929 */
81930@@ -440,7 +446,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
81931
81932 static int get_futex_value_locked(u32 *dest, u32 __user *from)
81933 {
81934- int ret;
81935+ unsigned long ret;
81936
81937 pagefault_disable();
81938 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
81939@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
81940 {
81941 u32 curval;
81942 int i;
81943+ mm_segment_t oldfs;
81944
81945 /*
81946 * This will fail and we want it. Some arch implementations do
81947@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
81948 * implementation, the non-functional ones will return
81949 * -ENOSYS.
81950 */
81951+ oldfs = get_fs();
81952+ set_fs(USER_DS);
81953 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
81954 futex_cmpxchg_enabled = 1;
81955+ set_fs(oldfs);
81956
81957 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
81958 plist_head_init(&futex_queues[i].chain);
81959diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
81960index f9f44fd..29885e4 100644
81961--- a/kernel/futex_compat.c
81962+++ b/kernel/futex_compat.c
81963@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
81964 return 0;
81965 }
81966
81967-static void __user *futex_uaddr(struct robust_list __user *entry,
81968+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
81969 compat_long_t futex_offset)
81970 {
81971 compat_uptr_t base = ptr_to_compat(entry);
81972diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
81973index 9b22d03..6295b62 100644
81974--- a/kernel/gcov/base.c
81975+++ b/kernel/gcov/base.c
81976@@ -102,11 +102,6 @@ void gcov_enable_events(void)
81977 }
81978
81979 #ifdef CONFIG_MODULES
81980-static inline int within(void *addr, void *start, unsigned long size)
81981-{
81982- return ((addr >= start) && (addr < start + size));
81983-}
81984-
81985 /* Update list and generate events when modules are unloaded. */
81986 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
81987 void *data)
81988@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
81989 prev = NULL;
81990 /* Remove entries located in module from linked list. */
81991 for (info = gcov_info_head; info; info = info->next) {
81992- if (within(info, mod->module_core, mod->core_size)) {
81993+ if (within_module_core_rw((unsigned long)info, mod)) {
81994 if (prev)
81995 prev->next = info->next;
81996 else
81997diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
81998index 2288fbd..0f3941f 100644
81999--- a/kernel/hrtimer.c
82000+++ b/kernel/hrtimer.c
82001@@ -1435,7 +1435,7 @@ void hrtimer_peek_ahead_timers(void)
82002 local_irq_restore(flags);
82003 }
82004
82005-static void run_hrtimer_softirq(struct softirq_action *h)
82006+static void run_hrtimer_softirq(void)
82007 {
82008 hrtimer_peek_ahead_timers();
82009 }
82010@@ -1770,7 +1770,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
82011 return NOTIFY_OK;
82012 }
82013
82014-static struct notifier_block __cpuinitdata hrtimers_nb = {
82015+static struct notifier_block hrtimers_nb = {
82016 .notifier_call = hrtimer_cpu_notify,
82017 };
82018
82019diff --git a/kernel/irq_work.c b/kernel/irq_work.c
82020index 55fcce6..0e4cf34 100644
82021--- a/kernel/irq_work.c
82022+++ b/kernel/irq_work.c
82023@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
82024 return NOTIFY_OK;
82025 }
82026
82027-static struct notifier_block cpu_notify;
82028+static struct notifier_block cpu_notify = {
82029+ .notifier_call = irq_work_cpu_notify,
82030+ .priority = 0,
82031+};
82032
82033 static __init int irq_work_init_cpu_notifier(void)
82034 {
82035- cpu_notify.notifier_call = irq_work_cpu_notify;
82036- cpu_notify.priority = 0;
82037 register_cpu_notifier(&cpu_notify);
82038 return 0;
82039 }
82040diff --git a/kernel/jump_label.c b/kernel/jump_label.c
82041index 60f48fa..7f3a770 100644
82042--- a/kernel/jump_label.c
82043+++ b/kernel/jump_label.c
82044@@ -13,6 +13,7 @@
82045 #include <linux/sort.h>
82046 #include <linux/err.h>
82047 #include <linux/static_key.h>
82048+#include <linux/mm.h>
82049
82050 #ifdef HAVE_JUMP_LABEL
82051
82052@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
82053
82054 size = (((unsigned long)stop - (unsigned long)start)
82055 / sizeof(struct jump_entry));
82056+ pax_open_kernel();
82057 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
82058+ pax_close_kernel();
82059 }
82060
82061 static void jump_label_update(struct static_key *key, int enable);
82062@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
82063 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
82064 struct jump_entry *iter;
82065
82066+ pax_open_kernel();
82067 for (iter = iter_start; iter < iter_stop; iter++) {
82068 if (within_module_init(iter->code, mod))
82069 iter->code = 0;
82070 }
82071+ pax_close_kernel();
82072 }
82073
82074 static int
82075diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
82076index 3127ad5..159d880 100644
82077--- a/kernel/kallsyms.c
82078+++ b/kernel/kallsyms.c
82079@@ -11,6 +11,9 @@
82080 * Changed the compression method from stem compression to "table lookup"
82081 * compression (see scripts/kallsyms.c for a more complete description)
82082 */
82083+#ifdef CONFIG_GRKERNSEC_HIDESYM
82084+#define __INCLUDED_BY_HIDESYM 1
82085+#endif
82086 #include <linux/kallsyms.h>
82087 #include <linux/module.h>
82088 #include <linux/init.h>
82089@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
82090
82091 static inline int is_kernel_inittext(unsigned long addr)
82092 {
82093+ if (system_state != SYSTEM_BOOTING)
82094+ return 0;
82095+
82096 if (addr >= (unsigned long)_sinittext
82097 && addr <= (unsigned long)_einittext)
82098 return 1;
82099 return 0;
82100 }
82101
82102+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82103+#ifdef CONFIG_MODULES
82104+static inline int is_module_text(unsigned long addr)
82105+{
82106+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
82107+ return 1;
82108+
82109+ addr = ktla_ktva(addr);
82110+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
82111+}
82112+#else
82113+static inline int is_module_text(unsigned long addr)
82114+{
82115+ return 0;
82116+}
82117+#endif
82118+#endif
82119+
82120 static inline int is_kernel_text(unsigned long addr)
82121 {
82122 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
82123@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
82124
82125 static inline int is_kernel(unsigned long addr)
82126 {
82127+
82128+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82129+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
82130+ return 1;
82131+
82132+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
82133+#else
82134 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
82135+#endif
82136+
82137 return 1;
82138 return in_gate_area_no_mm(addr);
82139 }
82140
82141 static int is_ksym_addr(unsigned long addr)
82142 {
82143+
82144+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82145+ if (is_module_text(addr))
82146+ return 0;
82147+#endif
82148+
82149 if (all_var)
82150 return is_kernel(addr);
82151
82152@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
82153
82154 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
82155 {
82156- iter->name[0] = '\0';
82157 iter->nameoff = get_symbol_offset(new_pos);
82158 iter->pos = new_pos;
82159 }
82160@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
82161 {
82162 struct kallsym_iter *iter = m->private;
82163
82164+#ifdef CONFIG_GRKERNSEC_HIDESYM
82165+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
82166+ return 0;
82167+#endif
82168+
82169 /* Some debugging symbols have no name. Ignore them. */
82170 if (!iter->name[0])
82171 return 0;
82172@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
82173 */
82174 type = iter->exported ? toupper(iter->type) :
82175 tolower(iter->type);
82176+
82177 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
82178 type, iter->name, iter->module_name);
82179 } else
82180@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
82181 struct kallsym_iter *iter;
82182 int ret;
82183
82184- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
82185+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
82186 if (!iter)
82187 return -ENOMEM;
82188 reset_iter(iter, 0);
82189diff --git a/kernel/kcmp.c b/kernel/kcmp.c
82190index e30ac0f..3528cac 100644
82191--- a/kernel/kcmp.c
82192+++ b/kernel/kcmp.c
82193@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
82194 struct task_struct *task1, *task2;
82195 int ret;
82196
82197+#ifdef CONFIG_GRKERNSEC
82198+ return -ENOSYS;
82199+#endif
82200+
82201 rcu_read_lock();
82202
82203 /*
82204diff --git a/kernel/kexec.c b/kernel/kexec.c
82205index 59f7b55..4022f65 100644
82206--- a/kernel/kexec.c
82207+++ b/kernel/kexec.c
82208@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
82209 unsigned long flags)
82210 {
82211 struct compat_kexec_segment in;
82212- struct kexec_segment out, __user *ksegments;
82213+ struct kexec_segment out;
82214+ struct kexec_segment __user *ksegments;
82215 unsigned long i, result;
82216
82217 /* Don't allow clients that don't understand the native
82218diff --git a/kernel/kmod.c b/kernel/kmod.c
82219index 8241906..d625f2c 100644
82220--- a/kernel/kmod.c
82221+++ b/kernel/kmod.c
82222@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
82223 kfree(info->argv);
82224 }
82225
82226-static int call_modprobe(char *module_name, int wait)
82227+static int call_modprobe(char *module_name, char *module_param, int wait)
82228 {
82229 struct subprocess_info *info;
82230 static char *envp[] = {
82231@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
82232 NULL
82233 };
82234
82235- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
82236+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
82237 if (!argv)
82238 goto out;
82239
82240@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
82241 argv[1] = "-q";
82242 argv[2] = "--";
82243 argv[3] = module_name; /* check free_modprobe_argv() */
82244- argv[4] = NULL;
82245+ argv[4] = module_param;
82246+ argv[5] = NULL;
82247
82248 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
82249 NULL, free_modprobe_argv, NULL);
82250@@ -129,9 +130,8 @@ out:
82251 * If module auto-loading support is disabled then this function
82252 * becomes a no-operation.
82253 */
82254-int __request_module(bool wait, const char *fmt, ...)
82255+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
82256 {
82257- va_list args;
82258 char module_name[MODULE_NAME_LEN];
82259 unsigned int max_modprobes;
82260 int ret;
82261@@ -147,9 +147,7 @@ int __request_module(bool wait, const char *fmt, ...)
82262 */
82263 WARN_ON_ONCE(wait && current_is_async());
82264
82265- va_start(args, fmt);
82266- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
82267- va_end(args);
82268+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
82269 if (ret >= MODULE_NAME_LEN)
82270 return -ENAMETOOLONG;
82271
82272@@ -157,6 +155,20 @@ int __request_module(bool wait, const char *fmt, ...)
82273 if (ret)
82274 return ret;
82275
82276+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82277+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82278+ /* hack to workaround consolekit/udisks stupidity */
82279+ read_lock(&tasklist_lock);
82280+ if (!strcmp(current->comm, "mount") &&
82281+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
82282+ read_unlock(&tasklist_lock);
82283+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
82284+ return -EPERM;
82285+ }
82286+ read_unlock(&tasklist_lock);
82287+ }
82288+#endif
82289+
82290 /* If modprobe needs a service that is in a module, we get a recursive
82291 * loop. Limit the number of running kmod threads to max_threads/2 or
82292 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
82293@@ -185,11 +197,52 @@ int __request_module(bool wait, const char *fmt, ...)
82294
82295 trace_module_request(module_name, wait, _RET_IP_);
82296
82297- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82298+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82299
82300 atomic_dec(&kmod_concurrent);
82301 return ret;
82302 }
82303+
82304+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
82305+{
82306+ va_list args;
82307+ int ret;
82308+
82309+ va_start(args, fmt);
82310+ ret = ____request_module(wait, module_param, fmt, args);
82311+ va_end(args);
82312+
82313+ return ret;
82314+}
82315+
82316+int __request_module(bool wait, const char *fmt, ...)
82317+{
82318+ va_list args;
82319+ int ret;
82320+
82321+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82322+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82323+ char module_param[MODULE_NAME_LEN];
82324+
82325+ memset(module_param, 0, sizeof(module_param));
82326+
82327+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
82328+
82329+ va_start(args, fmt);
82330+ ret = ____request_module(wait, module_param, fmt, args);
82331+ va_end(args);
82332+
82333+ return ret;
82334+ }
82335+#endif
82336+
82337+ va_start(args, fmt);
82338+ ret = ____request_module(wait, NULL, fmt, args);
82339+ va_end(args);
82340+
82341+ return ret;
82342+}
82343+
82344 EXPORT_SYMBOL(__request_module);
82345 #endif /* CONFIG_MODULES */
82346
82347@@ -300,7 +353,7 @@ static int wait_for_helper(void *data)
82348 *
82349 * Thus the __user pointer cast is valid here.
82350 */
82351- sys_wait4(pid, (int __user *)&ret, 0, NULL);
82352+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
82353
82354 /*
82355 * If ret is 0, either ____call_usermodehelper failed and the
82356@@ -651,7 +704,7 @@ EXPORT_SYMBOL(call_usermodehelper);
82357 static int proc_cap_handler(struct ctl_table *table, int write,
82358 void __user *buffer, size_t *lenp, loff_t *ppos)
82359 {
82360- struct ctl_table t;
82361+ ctl_table_no_const t;
82362 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
82363 kernel_cap_t new_cap;
82364 int err, i;
82365diff --git a/kernel/kprobes.c b/kernel/kprobes.c
82366index bddf3b2..233bf40 100644
82367--- a/kernel/kprobes.c
82368+++ b/kernel/kprobes.c
82369@@ -31,6 +31,9 @@
82370 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
82371 * <prasanna@in.ibm.com> added function-return probes.
82372 */
82373+#ifdef CONFIG_GRKERNSEC_HIDESYM
82374+#define __INCLUDED_BY_HIDESYM 1
82375+#endif
82376 #include <linux/kprobes.h>
82377 #include <linux/hash.h>
82378 #include <linux/init.h>
82379@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
82380 * kernel image and loaded module images reside. This is required
82381 * so x86_64 can correctly handle the %rip-relative fixups.
82382 */
82383- kip->insns = module_alloc(PAGE_SIZE);
82384+ kip->insns = module_alloc_exec(PAGE_SIZE);
82385 if (!kip->insns) {
82386 kfree(kip);
82387 return NULL;
82388@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
82389 */
82390 if (!list_is_singular(&kip->list)) {
82391 list_del(&kip->list);
82392- module_free(NULL, kip->insns);
82393+ module_free_exec(NULL, kip->insns);
82394 kfree(kip);
82395 }
82396 return 1;
82397@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
82398 {
82399 int i, err = 0;
82400 unsigned long offset = 0, size = 0;
82401- char *modname, namebuf[128];
82402+ char *modname, namebuf[KSYM_NAME_LEN];
82403 const char *symbol_name;
82404 void *addr;
82405 struct kprobe_blackpoint *kb;
82406@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
82407 kprobe_type = "k";
82408
82409 if (sym)
82410- seq_printf(pi, "%p %s %s+0x%x %s ",
82411+ seq_printf(pi, "%pK %s %s+0x%x %s ",
82412 p->addr, kprobe_type, sym, offset,
82413 (modname ? modname : " "));
82414 else
82415- seq_printf(pi, "%p %s %p ",
82416+ seq_printf(pi, "%pK %s %pK ",
82417 p->addr, kprobe_type, p->addr);
82418
82419 if (!pp)
82420@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
82421 const char *sym = NULL;
82422 unsigned int i = *(loff_t *) v;
82423 unsigned long offset = 0;
82424- char *modname, namebuf[128];
82425+ char *modname, namebuf[KSYM_NAME_LEN];
82426
82427 head = &kprobe_table[i];
82428 preempt_disable();
82429diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
82430index 6ada93c..dce7d5d 100644
82431--- a/kernel/ksysfs.c
82432+++ b/kernel/ksysfs.c
82433@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
82434 {
82435 if (count+1 > UEVENT_HELPER_PATH_LEN)
82436 return -ENOENT;
82437+ if (!capable(CAP_SYS_ADMIN))
82438+ return -EPERM;
82439 memcpy(uevent_helper, buf, count);
82440 uevent_helper[count] = '\0';
82441 if (count && uevent_helper[count-1] == '\n')
82442@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
82443 return count;
82444 }
82445
82446-static struct bin_attribute notes_attr = {
82447+static bin_attribute_no_const notes_attr __read_only = {
82448 .attr = {
82449 .name = "notes",
82450 .mode = S_IRUGO,
82451diff --git a/kernel/lockdep.c b/kernel/lockdep.c
82452index 1f3186b..bb7dbc6 100644
82453--- a/kernel/lockdep.c
82454+++ b/kernel/lockdep.c
82455@@ -596,6 +596,10 @@ static int static_obj(void *obj)
82456 end = (unsigned long) &_end,
82457 addr = (unsigned long) obj;
82458
82459+#ifdef CONFIG_PAX_KERNEXEC
82460+ start = ktla_ktva(start);
82461+#endif
82462+
82463 /*
82464 * static variable?
82465 */
82466@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
82467 if (!static_obj(lock->key)) {
82468 debug_locks_off();
82469 printk("INFO: trying to register non-static key.\n");
82470+ printk("lock:%pS key:%pS.\n", lock, lock->key);
82471 printk("the code is fine but needs lockdep annotation.\n");
82472 printk("turning off the locking correctness validator.\n");
82473 dump_stack();
82474@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
82475 if (!class)
82476 return 0;
82477 }
82478- atomic_inc((atomic_t *)&class->ops);
82479+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
82480 if (very_verbose(class)) {
82481 printk("\nacquire class [%p] %s", class->key, class->name);
82482 if (class->name_version > 1)
82483diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
82484index b2c71c5..7b88d63 100644
82485--- a/kernel/lockdep_proc.c
82486+++ b/kernel/lockdep_proc.c
82487@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
82488 return 0;
82489 }
82490
82491- seq_printf(m, "%p", class->key);
82492+ seq_printf(m, "%pK", class->key);
82493 #ifdef CONFIG_DEBUG_LOCKDEP
82494 seq_printf(m, " OPS:%8ld", class->ops);
82495 #endif
82496@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
82497
82498 list_for_each_entry(entry, &class->locks_after, entry) {
82499 if (entry->distance == 1) {
82500- seq_printf(m, " -> [%p] ", entry->class->key);
82501+ seq_printf(m, " -> [%pK] ", entry->class->key);
82502 print_name(m, entry->class);
82503 seq_puts(m, "\n");
82504 }
82505@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
82506 if (!class->key)
82507 continue;
82508
82509- seq_printf(m, "[%p] ", class->key);
82510+ seq_printf(m, "[%pK] ", class->key);
82511 print_name(m, class);
82512 seq_puts(m, "\n");
82513 }
82514@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82515 if (!i)
82516 seq_line(m, '-', 40-namelen, namelen);
82517
82518- snprintf(ip, sizeof(ip), "[<%p>]",
82519+ snprintf(ip, sizeof(ip), "[<%pK>]",
82520 (void *)class->contention_point[i]);
82521 seq_printf(m, "%40s %14lu %29s %pS\n",
82522 name, stats->contention_point[i],
82523@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82524 if (!i)
82525 seq_line(m, '-', 40-namelen, namelen);
82526
82527- snprintf(ip, sizeof(ip), "[<%p>]",
82528+ snprintf(ip, sizeof(ip), "[<%pK>]",
82529 (void *)class->contending_point[i]);
82530 seq_printf(m, "%40s %14lu %29s %pS\n",
82531 name, stats->contending_point[i],
82532diff --git a/kernel/module.c b/kernel/module.c
82533index fa53db8..6f17200 100644
82534--- a/kernel/module.c
82535+++ b/kernel/module.c
82536@@ -61,6 +61,7 @@
82537 #include <linux/pfn.h>
82538 #include <linux/bsearch.h>
82539 #include <linux/fips.h>
82540+#include <linux/grsecurity.h>
82541 #include <uapi/linux/module.h>
82542 #include "module-internal.h"
82543
82544@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
82545
82546 /* Bounds of module allocation, for speeding __module_address.
82547 * Protected by module_mutex. */
82548-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
82549+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
82550+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
82551
82552 int register_module_notifier(struct notifier_block * nb)
82553 {
82554@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82555 return true;
82556
82557 list_for_each_entry_rcu(mod, &modules, list) {
82558- struct symsearch arr[] = {
82559+ struct symsearch modarr[] = {
82560 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
82561 NOT_GPL_ONLY, false },
82562 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
82563@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82564 if (mod->state == MODULE_STATE_UNFORMED)
82565 continue;
82566
82567- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
82568+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
82569 return true;
82570 }
82571 return false;
82572@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
82573 static int percpu_modalloc(struct module *mod,
82574 unsigned long size, unsigned long align)
82575 {
82576- if (align > PAGE_SIZE) {
82577+ if (align-1 >= PAGE_SIZE) {
82578 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
82579 mod->name, align, PAGE_SIZE);
82580 align = PAGE_SIZE;
82581@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
82582 static ssize_t show_coresize(struct module_attribute *mattr,
82583 struct module_kobject *mk, char *buffer)
82584 {
82585- return sprintf(buffer, "%u\n", mk->mod->core_size);
82586+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
82587 }
82588
82589 static struct module_attribute modinfo_coresize =
82590@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
82591 static ssize_t show_initsize(struct module_attribute *mattr,
82592 struct module_kobject *mk, char *buffer)
82593 {
82594- return sprintf(buffer, "%u\n", mk->mod->init_size);
82595+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
82596 }
82597
82598 static struct module_attribute modinfo_initsize =
82599@@ -1313,7 +1315,7 @@ resolve_symbol_wait(struct module *mod,
82600 */
82601 #ifdef CONFIG_SYSFS
82602
82603-#ifdef CONFIG_KALLSYMS
82604+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82605 static inline bool sect_empty(const Elf_Shdr *sect)
82606 {
82607 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
82608@@ -1453,7 +1455,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
82609 {
82610 unsigned int notes, loaded, i;
82611 struct module_notes_attrs *notes_attrs;
82612- struct bin_attribute *nattr;
82613+ bin_attribute_no_const *nattr;
82614
82615 /* failed to create section attributes, so can't create notes */
82616 if (!mod->sect_attrs)
82617@@ -1565,7 +1567,7 @@ static void del_usage_links(struct module *mod)
82618 static int module_add_modinfo_attrs(struct module *mod)
82619 {
82620 struct module_attribute *attr;
82621- struct module_attribute *temp_attr;
82622+ module_attribute_no_const *temp_attr;
82623 int error = 0;
82624 int i;
82625
82626@@ -1779,21 +1781,21 @@ static void set_section_ro_nx(void *base,
82627
82628 static void unset_module_core_ro_nx(struct module *mod)
82629 {
82630- set_page_attributes(mod->module_core + mod->core_text_size,
82631- mod->module_core + mod->core_size,
82632+ set_page_attributes(mod->module_core_rw,
82633+ mod->module_core_rw + mod->core_size_rw,
82634 set_memory_x);
82635- set_page_attributes(mod->module_core,
82636- mod->module_core + mod->core_ro_size,
82637+ set_page_attributes(mod->module_core_rx,
82638+ mod->module_core_rx + mod->core_size_rx,
82639 set_memory_rw);
82640 }
82641
82642 static void unset_module_init_ro_nx(struct module *mod)
82643 {
82644- set_page_attributes(mod->module_init + mod->init_text_size,
82645- mod->module_init + mod->init_size,
82646+ set_page_attributes(mod->module_init_rw,
82647+ mod->module_init_rw + mod->init_size_rw,
82648 set_memory_x);
82649- set_page_attributes(mod->module_init,
82650- mod->module_init + mod->init_ro_size,
82651+ set_page_attributes(mod->module_init_rx,
82652+ mod->module_init_rx + mod->init_size_rx,
82653 set_memory_rw);
82654 }
82655
82656@@ -1806,14 +1808,14 @@ void set_all_modules_text_rw(void)
82657 list_for_each_entry_rcu(mod, &modules, list) {
82658 if (mod->state == MODULE_STATE_UNFORMED)
82659 continue;
82660- if ((mod->module_core) && (mod->core_text_size)) {
82661- set_page_attributes(mod->module_core,
82662- mod->module_core + mod->core_text_size,
82663+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82664+ set_page_attributes(mod->module_core_rx,
82665+ mod->module_core_rx + mod->core_size_rx,
82666 set_memory_rw);
82667 }
82668- if ((mod->module_init) && (mod->init_text_size)) {
82669- set_page_attributes(mod->module_init,
82670- mod->module_init + mod->init_text_size,
82671+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82672+ set_page_attributes(mod->module_init_rx,
82673+ mod->module_init_rx + mod->init_size_rx,
82674 set_memory_rw);
82675 }
82676 }
82677@@ -1829,14 +1831,14 @@ void set_all_modules_text_ro(void)
82678 list_for_each_entry_rcu(mod, &modules, list) {
82679 if (mod->state == MODULE_STATE_UNFORMED)
82680 continue;
82681- if ((mod->module_core) && (mod->core_text_size)) {
82682- set_page_attributes(mod->module_core,
82683- mod->module_core + mod->core_text_size,
82684+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82685+ set_page_attributes(mod->module_core_rx,
82686+ mod->module_core_rx + mod->core_size_rx,
82687 set_memory_ro);
82688 }
82689- if ((mod->module_init) && (mod->init_text_size)) {
82690- set_page_attributes(mod->module_init,
82691- mod->module_init + mod->init_text_size,
82692+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82693+ set_page_attributes(mod->module_init_rx,
82694+ mod->module_init_rx + mod->init_size_rx,
82695 set_memory_ro);
82696 }
82697 }
82698@@ -1887,16 +1889,19 @@ static void free_module(struct module *mod)
82699
82700 /* This may be NULL, but that's OK */
82701 unset_module_init_ro_nx(mod);
82702- module_free(mod, mod->module_init);
82703+ module_free(mod, mod->module_init_rw);
82704+ module_free_exec(mod, mod->module_init_rx);
82705 kfree(mod->args);
82706 percpu_modfree(mod);
82707
82708 /* Free lock-classes: */
82709- lockdep_free_key_range(mod->module_core, mod->core_size);
82710+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
82711+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
82712
82713 /* Finally, free the core (containing the module structure) */
82714 unset_module_core_ro_nx(mod);
82715- module_free(mod, mod->module_core);
82716+ module_free_exec(mod, mod->module_core_rx);
82717+ module_free(mod, mod->module_core_rw);
82718
82719 #ifdef CONFIG_MPU
82720 update_protections(current->mm);
82721@@ -1966,9 +1971,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82722 int ret = 0;
82723 const struct kernel_symbol *ksym;
82724
82725+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82726+ int is_fs_load = 0;
82727+ int register_filesystem_found = 0;
82728+ char *p;
82729+
82730+ p = strstr(mod->args, "grsec_modharden_fs");
82731+ if (p) {
82732+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
82733+ /* copy \0 as well */
82734+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
82735+ is_fs_load = 1;
82736+ }
82737+#endif
82738+
82739 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
82740 const char *name = info->strtab + sym[i].st_name;
82741
82742+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82743+ /* it's a real shame this will never get ripped and copied
82744+ upstream! ;(
82745+ */
82746+ if (is_fs_load && !strcmp(name, "register_filesystem"))
82747+ register_filesystem_found = 1;
82748+#endif
82749+
82750 switch (sym[i].st_shndx) {
82751 case SHN_COMMON:
82752 /* We compiled with -fno-common. These are not
82753@@ -1989,7 +2016,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82754 ksym = resolve_symbol_wait(mod, info, name);
82755 /* Ok if resolved. */
82756 if (ksym && !IS_ERR(ksym)) {
82757+ pax_open_kernel();
82758 sym[i].st_value = ksym->value;
82759+ pax_close_kernel();
82760 break;
82761 }
82762
82763@@ -2008,11 +2037,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82764 secbase = (unsigned long)mod_percpu(mod);
82765 else
82766 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
82767+ pax_open_kernel();
82768 sym[i].st_value += secbase;
82769+ pax_close_kernel();
82770 break;
82771 }
82772 }
82773
82774+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82775+ if (is_fs_load && !register_filesystem_found) {
82776+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
82777+ ret = -EPERM;
82778+ }
82779+#endif
82780+
82781 return ret;
82782 }
82783
82784@@ -2096,22 +2134,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
82785 || s->sh_entsize != ~0UL
82786 || strstarts(sname, ".init"))
82787 continue;
82788- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
82789+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82790+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
82791+ else
82792+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
82793 pr_debug("\t%s\n", sname);
82794 }
82795- switch (m) {
82796- case 0: /* executable */
82797- mod->core_size = debug_align(mod->core_size);
82798- mod->core_text_size = mod->core_size;
82799- break;
82800- case 1: /* RO: text and ro-data */
82801- mod->core_size = debug_align(mod->core_size);
82802- mod->core_ro_size = mod->core_size;
82803- break;
82804- case 3: /* whole core */
82805- mod->core_size = debug_align(mod->core_size);
82806- break;
82807- }
82808 }
82809
82810 pr_debug("Init section allocation order:\n");
82811@@ -2125,23 +2153,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
82812 || s->sh_entsize != ~0UL
82813 || !strstarts(sname, ".init"))
82814 continue;
82815- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
82816- | INIT_OFFSET_MASK);
82817+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82818+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
82819+ else
82820+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
82821+ s->sh_entsize |= INIT_OFFSET_MASK;
82822 pr_debug("\t%s\n", sname);
82823 }
82824- switch (m) {
82825- case 0: /* executable */
82826- mod->init_size = debug_align(mod->init_size);
82827- mod->init_text_size = mod->init_size;
82828- break;
82829- case 1: /* RO: text and ro-data */
82830- mod->init_size = debug_align(mod->init_size);
82831- mod->init_ro_size = mod->init_size;
82832- break;
82833- case 3: /* whole init */
82834- mod->init_size = debug_align(mod->init_size);
82835- break;
82836- }
82837 }
82838 }
82839
82840@@ -2314,7 +2332,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82841
82842 /* Put symbol section at end of init part of module. */
82843 symsect->sh_flags |= SHF_ALLOC;
82844- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
82845+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
82846 info->index.sym) | INIT_OFFSET_MASK;
82847 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
82848
82849@@ -2331,13 +2349,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82850 }
82851
82852 /* Append room for core symbols at end of core part. */
82853- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
82854- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
82855- mod->core_size += strtab_size;
82856+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
82857+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
82858+ mod->core_size_rx += strtab_size;
82859
82860 /* Put string table section at end of init part of module. */
82861 strsect->sh_flags |= SHF_ALLOC;
82862- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
82863+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
82864 info->index.str) | INIT_OFFSET_MASK;
82865 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
82866 }
82867@@ -2355,12 +2373,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82868 /* Make sure we get permanent strtab: don't use info->strtab. */
82869 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
82870
82871+ pax_open_kernel();
82872+
82873 /* Set types up while we still have access to sections. */
82874 for (i = 0; i < mod->num_symtab; i++)
82875 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
82876
82877- mod->core_symtab = dst = mod->module_core + info->symoffs;
82878- mod->core_strtab = s = mod->module_core + info->stroffs;
82879+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
82880+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
82881 src = mod->symtab;
82882 for (ndst = i = 0; i < mod->num_symtab; i++) {
82883 if (i == 0 ||
82884@@ -2372,6 +2392,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82885 }
82886 }
82887 mod->core_num_syms = ndst;
82888+
82889+ pax_close_kernel();
82890 }
82891 #else
82892 static inline void layout_symtab(struct module *mod, struct load_info *info)
82893@@ -2405,17 +2427,33 @@ void * __weak module_alloc(unsigned long size)
82894 return vmalloc_exec(size);
82895 }
82896
82897-static void *module_alloc_update_bounds(unsigned long size)
82898+static void *module_alloc_update_bounds_rw(unsigned long size)
82899 {
82900 void *ret = module_alloc(size);
82901
82902 if (ret) {
82903 mutex_lock(&module_mutex);
82904 /* Update module bounds. */
82905- if ((unsigned long)ret < module_addr_min)
82906- module_addr_min = (unsigned long)ret;
82907- if ((unsigned long)ret + size > module_addr_max)
82908- module_addr_max = (unsigned long)ret + size;
82909+ if ((unsigned long)ret < module_addr_min_rw)
82910+ module_addr_min_rw = (unsigned long)ret;
82911+ if ((unsigned long)ret + size > module_addr_max_rw)
82912+ module_addr_max_rw = (unsigned long)ret + size;
82913+ mutex_unlock(&module_mutex);
82914+ }
82915+ return ret;
82916+}
82917+
82918+static void *module_alloc_update_bounds_rx(unsigned long size)
82919+{
82920+ void *ret = module_alloc_exec(size);
82921+
82922+ if (ret) {
82923+ mutex_lock(&module_mutex);
82924+ /* Update module bounds. */
82925+ if ((unsigned long)ret < module_addr_min_rx)
82926+ module_addr_min_rx = (unsigned long)ret;
82927+ if ((unsigned long)ret + size > module_addr_max_rx)
82928+ module_addr_max_rx = (unsigned long)ret + size;
82929 mutex_unlock(&module_mutex);
82930 }
82931 return ret;
82932@@ -2691,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
82933 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82934 {
82935 const char *modmagic = get_modinfo(info, "vermagic");
82936+ const char *license = get_modinfo(info, "license");
82937 int err;
82938
82939+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
82940+ if (!license || !license_is_gpl_compatible(license))
82941+ return -ENOEXEC;
82942+#endif
82943+
82944 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
82945 modmagic = NULL;
82946
82947@@ -2718,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82948 }
82949
82950 /* Set up license info based on the info section */
82951- set_license(mod, get_modinfo(info, "license"));
82952+ set_license(mod, license);
82953
82954 return 0;
82955 }
82956@@ -2799,7 +2843,7 @@ static int move_module(struct module *mod, struct load_info *info)
82957 void *ptr;
82958
82959 /* Do the allocs. */
82960- ptr = module_alloc_update_bounds(mod->core_size);
82961+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
82962 /*
82963 * The pointer to this block is stored in the module structure
82964 * which is inside the block. Just mark it as not being a
82965@@ -2809,11 +2853,11 @@ static int move_module(struct module *mod, struct load_info *info)
82966 if (!ptr)
82967 return -ENOMEM;
82968
82969- memset(ptr, 0, mod->core_size);
82970- mod->module_core = ptr;
82971+ memset(ptr, 0, mod->core_size_rw);
82972+ mod->module_core_rw = ptr;
82973
82974- if (mod->init_size) {
82975- ptr = module_alloc_update_bounds(mod->init_size);
82976+ if (mod->init_size_rw) {
82977+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
82978 /*
82979 * The pointer to this block is stored in the module structure
82980 * which is inside the block. This block doesn't need to be
82981@@ -2822,13 +2866,45 @@ static int move_module(struct module *mod, struct load_info *info)
82982 */
82983 kmemleak_ignore(ptr);
82984 if (!ptr) {
82985- module_free(mod, mod->module_core);
82986+ module_free(mod, mod->module_core_rw);
82987 return -ENOMEM;
82988 }
82989- memset(ptr, 0, mod->init_size);
82990- mod->module_init = ptr;
82991+ memset(ptr, 0, mod->init_size_rw);
82992+ mod->module_init_rw = ptr;
82993 } else
82994- mod->module_init = NULL;
82995+ mod->module_init_rw = NULL;
82996+
82997+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
82998+ kmemleak_not_leak(ptr);
82999+ if (!ptr) {
83000+ if (mod->module_init_rw)
83001+ module_free(mod, mod->module_init_rw);
83002+ module_free(mod, mod->module_core_rw);
83003+ return -ENOMEM;
83004+ }
83005+
83006+ pax_open_kernel();
83007+ memset(ptr, 0, mod->core_size_rx);
83008+ pax_close_kernel();
83009+ mod->module_core_rx = ptr;
83010+
83011+ if (mod->init_size_rx) {
83012+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
83013+ kmemleak_ignore(ptr);
83014+ if (!ptr && mod->init_size_rx) {
83015+ module_free_exec(mod, mod->module_core_rx);
83016+ if (mod->module_init_rw)
83017+ module_free(mod, mod->module_init_rw);
83018+ module_free(mod, mod->module_core_rw);
83019+ return -ENOMEM;
83020+ }
83021+
83022+ pax_open_kernel();
83023+ memset(ptr, 0, mod->init_size_rx);
83024+ pax_close_kernel();
83025+ mod->module_init_rx = ptr;
83026+ } else
83027+ mod->module_init_rx = NULL;
83028
83029 /* Transfer each section which specifies SHF_ALLOC */
83030 pr_debug("final section addresses:\n");
83031@@ -2839,16 +2915,45 @@ static int move_module(struct module *mod, struct load_info *info)
83032 if (!(shdr->sh_flags & SHF_ALLOC))
83033 continue;
83034
83035- if (shdr->sh_entsize & INIT_OFFSET_MASK)
83036- dest = mod->module_init
83037- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83038- else
83039- dest = mod->module_core + shdr->sh_entsize;
83040+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
83041+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83042+ dest = mod->module_init_rw
83043+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83044+ else
83045+ dest = mod->module_init_rx
83046+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
83047+ } else {
83048+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
83049+ dest = mod->module_core_rw + shdr->sh_entsize;
83050+ else
83051+ dest = mod->module_core_rx + shdr->sh_entsize;
83052+ }
83053+
83054+ if (shdr->sh_type != SHT_NOBITS) {
83055+
83056+#ifdef CONFIG_PAX_KERNEXEC
83057+#ifdef CONFIG_X86_64
83058+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
83059+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
83060+#endif
83061+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
83062+ pax_open_kernel();
83063+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83064+ pax_close_kernel();
83065+ } else
83066+#endif
83067
83068- if (shdr->sh_type != SHT_NOBITS)
83069 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
83070+ }
83071 /* Update sh_addr to point to copy in image. */
83072- shdr->sh_addr = (unsigned long)dest;
83073+
83074+#ifdef CONFIG_PAX_KERNEXEC
83075+ if (shdr->sh_flags & SHF_EXECINSTR)
83076+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
83077+ else
83078+#endif
83079+
83080+ shdr->sh_addr = (unsigned long)dest;
83081 pr_debug("\t0x%lx %s\n",
83082 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
83083 }
83084@@ -2905,12 +3010,12 @@ static void flush_module_icache(const struct module *mod)
83085 * Do it before processing of module parameters, so the module
83086 * can provide parameter accessor functions of its own.
83087 */
83088- if (mod->module_init)
83089- flush_icache_range((unsigned long)mod->module_init,
83090- (unsigned long)mod->module_init
83091- + mod->init_size);
83092- flush_icache_range((unsigned long)mod->module_core,
83093- (unsigned long)mod->module_core + mod->core_size);
83094+ if (mod->module_init_rx)
83095+ flush_icache_range((unsigned long)mod->module_init_rx,
83096+ (unsigned long)mod->module_init_rx
83097+ + mod->init_size_rx);
83098+ flush_icache_range((unsigned long)mod->module_core_rx,
83099+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
83100
83101 set_fs(old_fs);
83102 }
83103@@ -2977,8 +3082,10 @@ static int alloc_module_percpu(struct module *mod, struct load_info *info)
83104 static void module_deallocate(struct module *mod, struct load_info *info)
83105 {
83106 percpu_modfree(mod);
83107- module_free(mod, mod->module_init);
83108- module_free(mod, mod->module_core);
83109+ module_free_exec(mod, mod->module_init_rx);
83110+ module_free_exec(mod, mod->module_core_rx);
83111+ module_free(mod, mod->module_init_rw);
83112+ module_free(mod, mod->module_core_rw);
83113 }
83114
83115 int __weak module_finalize(const Elf_Ehdr *hdr,
83116@@ -2991,7 +3098,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
83117 static int post_relocation(struct module *mod, const struct load_info *info)
83118 {
83119 /* Sort exception table now relocations are done. */
83120+ pax_open_kernel();
83121 sort_extable(mod->extable, mod->extable + mod->num_exentries);
83122+ pax_close_kernel();
83123
83124 /* Copy relocated percpu area over. */
83125 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
83126@@ -3045,16 +3154,16 @@ static int do_init_module(struct module *mod)
83127 MODULE_STATE_COMING, mod);
83128
83129 /* Set RO and NX regions for core */
83130- set_section_ro_nx(mod->module_core,
83131- mod->core_text_size,
83132- mod->core_ro_size,
83133- mod->core_size);
83134+ set_section_ro_nx(mod->module_core_rx,
83135+ mod->core_size_rx,
83136+ mod->core_size_rx,
83137+ mod->core_size_rx);
83138
83139 /* Set RO and NX regions for init */
83140- set_section_ro_nx(mod->module_init,
83141- mod->init_text_size,
83142- mod->init_ro_size,
83143- mod->init_size);
83144+ set_section_ro_nx(mod->module_init_rx,
83145+ mod->init_size_rx,
83146+ mod->init_size_rx,
83147+ mod->init_size_rx);
83148
83149 do_mod_ctors(mod);
83150 /* Start the module */
83151@@ -3116,11 +3225,12 @@ static int do_init_module(struct module *mod)
83152 mod->strtab = mod->core_strtab;
83153 #endif
83154 unset_module_init_ro_nx(mod);
83155- module_free(mod, mod->module_init);
83156- mod->module_init = NULL;
83157- mod->init_size = 0;
83158- mod->init_ro_size = 0;
83159- mod->init_text_size = 0;
83160+ module_free(mod, mod->module_init_rw);
83161+ module_free_exec(mod, mod->module_init_rx);
83162+ mod->module_init_rw = NULL;
83163+ mod->module_init_rx = NULL;
83164+ mod->init_size_rw = 0;
83165+ mod->init_size_rx = 0;
83166 mutex_unlock(&module_mutex);
83167 wake_up_all(&module_wq);
83168
83169@@ -3252,9 +3362,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
83170 if (err)
83171 goto free_unload;
83172
83173+ /* Now copy in args */
83174+ mod->args = strndup_user(uargs, ~0UL >> 1);
83175+ if (IS_ERR(mod->args)) {
83176+ err = PTR_ERR(mod->args);
83177+ goto free_unload;
83178+ }
83179+
83180 /* Set up MODINFO_ATTR fields */
83181 setup_modinfo(mod, info);
83182
83183+#ifdef CONFIG_GRKERNSEC_MODHARDEN
83184+ {
83185+ char *p, *p2;
83186+
83187+ if (strstr(mod->args, "grsec_modharden_netdev")) {
83188+ 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);
83189+ err = -EPERM;
83190+ goto free_modinfo;
83191+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
83192+ p += sizeof("grsec_modharden_normal") - 1;
83193+ p2 = strstr(p, "_");
83194+ if (p2) {
83195+ *p2 = '\0';
83196+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
83197+ *p2 = '_';
83198+ }
83199+ err = -EPERM;
83200+ goto free_modinfo;
83201+ }
83202+ }
83203+#endif
83204+
83205 /* Fix up syms, so that st_value is a pointer to location. */
83206 err = simplify_symbols(mod, info);
83207 if (err < 0)
83208@@ -3270,13 +3409,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
83209
83210 flush_module_icache(mod);
83211
83212- /* Now copy in args */
83213- mod->args = strndup_user(uargs, ~0UL >> 1);
83214- if (IS_ERR(mod->args)) {
83215- err = PTR_ERR(mod->args);
83216- goto free_arch_cleanup;
83217- }
83218-
83219 dynamic_debug_setup(info->debug, info->num_debug);
83220
83221 /* Finally it's fully formed, ready to start executing. */
83222@@ -3311,11 +3443,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
83223 ddebug_cleanup:
83224 dynamic_debug_remove(info->debug);
83225 synchronize_sched();
83226- kfree(mod->args);
83227- free_arch_cleanup:
83228 module_arch_cleanup(mod);
83229 free_modinfo:
83230 free_modinfo(mod);
83231+ kfree(mod->args);
83232 free_unload:
83233 module_unload_free(mod);
83234 unlink_mod:
83235@@ -3398,10 +3529,16 @@ static const char *get_ksymbol(struct module *mod,
83236 unsigned long nextval;
83237
83238 /* At worse, next value is at end of module */
83239- if (within_module_init(addr, mod))
83240- nextval = (unsigned long)mod->module_init+mod->init_text_size;
83241+ if (within_module_init_rx(addr, mod))
83242+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
83243+ else if (within_module_init_rw(addr, mod))
83244+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
83245+ else if (within_module_core_rx(addr, mod))
83246+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
83247+ else if (within_module_core_rw(addr, mod))
83248+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
83249 else
83250- nextval = (unsigned long)mod->module_core+mod->core_text_size;
83251+ return NULL;
83252
83253 /* Scan for closest preceding symbol, and next symbol. (ELF
83254 starts real symbols at 1). */
83255@@ -3654,7 +3791,7 @@ static int m_show(struct seq_file *m, void *p)
83256 return 0;
83257
83258 seq_printf(m, "%s %u",
83259- mod->name, mod->init_size + mod->core_size);
83260+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
83261 print_unload_info(m, mod);
83262
83263 /* Informative for users. */
83264@@ -3663,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
83265 mod->state == MODULE_STATE_COMING ? "Loading":
83266 "Live");
83267 /* Used by oprofile and other similar tools. */
83268- seq_printf(m, " 0x%pK", mod->module_core);
83269+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
83270
83271 /* Taints info */
83272 if (mod->taints)
83273@@ -3699,7 +3836,17 @@ static const struct file_operations proc_modules_operations = {
83274
83275 static int __init proc_modules_init(void)
83276 {
83277+#ifndef CONFIG_GRKERNSEC_HIDESYM
83278+#ifdef CONFIG_GRKERNSEC_PROC_USER
83279+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83280+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83281+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
83282+#else
83283 proc_create("modules", 0, NULL, &proc_modules_operations);
83284+#endif
83285+#else
83286+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83287+#endif
83288 return 0;
83289 }
83290 module_init(proc_modules_init);
83291@@ -3760,14 +3907,14 @@ struct module *__module_address(unsigned long addr)
83292 {
83293 struct module *mod;
83294
83295- if (addr < module_addr_min || addr > module_addr_max)
83296+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
83297+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
83298 return NULL;
83299
83300 list_for_each_entry_rcu(mod, &modules, list) {
83301 if (mod->state == MODULE_STATE_UNFORMED)
83302 continue;
83303- if (within_module_core(addr, mod)
83304- || within_module_init(addr, mod))
83305+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
83306 return mod;
83307 }
83308 return NULL;
83309@@ -3802,11 +3949,20 @@ bool is_module_text_address(unsigned long addr)
83310 */
83311 struct module *__module_text_address(unsigned long addr)
83312 {
83313- struct module *mod = __module_address(addr);
83314+ struct module *mod;
83315+
83316+#ifdef CONFIG_X86_32
83317+ addr = ktla_ktva(addr);
83318+#endif
83319+
83320+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
83321+ return NULL;
83322+
83323+ mod = __module_address(addr);
83324+
83325 if (mod) {
83326 /* Make sure it's within the text section. */
83327- if (!within(addr, mod->module_init, mod->init_text_size)
83328- && !within(addr, mod->module_core, mod->core_text_size))
83329+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
83330 mod = NULL;
83331 }
83332 return mod;
83333diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
83334index 7e3443f..b2a1e6b 100644
83335--- a/kernel/mutex-debug.c
83336+++ b/kernel/mutex-debug.c
83337@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
83338 }
83339
83340 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83341- struct thread_info *ti)
83342+ struct task_struct *task)
83343 {
83344 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
83345
83346 /* Mark the current thread as blocked on the lock: */
83347- ti->task->blocked_on = waiter;
83348+ task->blocked_on = waiter;
83349 }
83350
83351 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83352- struct thread_info *ti)
83353+ struct task_struct *task)
83354 {
83355 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
83356- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
83357- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
83358- ti->task->blocked_on = NULL;
83359+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
83360+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
83361+ task->blocked_on = NULL;
83362
83363 list_del_init(&waiter->list);
83364 waiter->task = NULL;
83365diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
83366index 0799fd3..d06ae3b 100644
83367--- a/kernel/mutex-debug.h
83368+++ b/kernel/mutex-debug.h
83369@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
83370 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
83371 extern void debug_mutex_add_waiter(struct mutex *lock,
83372 struct mutex_waiter *waiter,
83373- struct thread_info *ti);
83374+ struct task_struct *task);
83375 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83376- struct thread_info *ti);
83377+ struct task_struct *task);
83378 extern void debug_mutex_unlock(struct mutex *lock);
83379 extern void debug_mutex_init(struct mutex *lock, const char *name,
83380 struct lock_class_key *key);
83381diff --git a/kernel/mutex.c b/kernel/mutex.c
83382index ad53a66..f1bf8bc 100644
83383--- a/kernel/mutex.c
83384+++ b/kernel/mutex.c
83385@@ -134,7 +134,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
83386 node->locked = 1;
83387 return;
83388 }
83389- ACCESS_ONCE(prev->next) = node;
83390+ ACCESS_ONCE_RW(prev->next) = node;
83391 smp_wmb();
83392 /* Wait until the lock holder passes the lock down */
83393 while (!ACCESS_ONCE(node->locked))
83394@@ -155,7 +155,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
83395 while (!(next = ACCESS_ONCE(node->next)))
83396 arch_mutex_cpu_relax();
83397 }
83398- ACCESS_ONCE(next->locked) = 1;
83399+ ACCESS_ONCE_RW(next->locked) = 1;
83400 smp_wmb();
83401 }
83402
83403@@ -341,7 +341,7 @@ slowpath:
83404 spin_lock_mutex(&lock->wait_lock, flags);
83405
83406 debug_mutex_lock_common(lock, &waiter);
83407- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
83408+ debug_mutex_add_waiter(lock, &waiter, task);
83409
83410 /* add waiting tasks to the end of the waitqueue (FIFO): */
83411 list_add_tail(&waiter.list, &lock->wait_list);
83412@@ -371,8 +371,7 @@ slowpath:
83413 * TASK_UNINTERRUPTIBLE case.)
83414 */
83415 if (unlikely(signal_pending_state(state, task))) {
83416- mutex_remove_waiter(lock, &waiter,
83417- task_thread_info(task));
83418+ mutex_remove_waiter(lock, &waiter, task);
83419 mutex_release(&lock->dep_map, 1, ip);
83420 spin_unlock_mutex(&lock->wait_lock, flags);
83421
83422@@ -391,7 +390,7 @@ slowpath:
83423 done:
83424 lock_acquired(&lock->dep_map, ip);
83425 /* got the lock - rejoice! */
83426- mutex_remove_waiter(lock, &waiter, current_thread_info());
83427+ mutex_remove_waiter(lock, &waiter, task);
83428 mutex_set_owner(lock);
83429
83430 /* set it to 0 if there are no waiters left: */
83431diff --git a/kernel/notifier.c b/kernel/notifier.c
83432index 2d5cc4c..d9ea600 100644
83433--- a/kernel/notifier.c
83434+++ b/kernel/notifier.c
83435@@ -5,6 +5,7 @@
83436 #include <linux/rcupdate.h>
83437 #include <linux/vmalloc.h>
83438 #include <linux/reboot.h>
83439+#include <linux/mm.h>
83440
83441 /*
83442 * Notifier list for kernel code which wants to be called
83443@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
83444 while ((*nl) != NULL) {
83445 if (n->priority > (*nl)->priority)
83446 break;
83447- nl = &((*nl)->next);
83448+ nl = (struct notifier_block **)&((*nl)->next);
83449 }
83450- n->next = *nl;
83451+ pax_open_kernel();
83452+ *(const void **)&n->next = *nl;
83453 rcu_assign_pointer(*nl, n);
83454+ pax_close_kernel();
83455 return 0;
83456 }
83457
83458@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
83459 return 0;
83460 if (n->priority > (*nl)->priority)
83461 break;
83462- nl = &((*nl)->next);
83463+ nl = (struct notifier_block **)&((*nl)->next);
83464 }
83465- n->next = *nl;
83466+ pax_open_kernel();
83467+ *(const void **)&n->next = *nl;
83468 rcu_assign_pointer(*nl, n);
83469+ pax_close_kernel();
83470 return 0;
83471 }
83472
83473@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
83474 {
83475 while ((*nl) != NULL) {
83476 if ((*nl) == n) {
83477+ pax_open_kernel();
83478 rcu_assign_pointer(*nl, n->next);
83479+ pax_close_kernel();
83480 return 0;
83481 }
83482- nl = &((*nl)->next);
83483+ nl = (struct notifier_block **)&((*nl)->next);
83484 }
83485 return -ENOENT;
83486 }
83487diff --git a/kernel/panic.c b/kernel/panic.c
83488index 167ec09..0dda5f9 100644
83489--- a/kernel/panic.c
83490+++ b/kernel/panic.c
83491@@ -400,7 +400,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
83492 unsigned taint, struct slowpath_args *args)
83493 {
83494 printk(KERN_WARNING "------------[ cut here ]------------\n");
83495- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
83496+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
83497
83498 if (args)
83499 vprintk(args->fmt, args->args);
83500@@ -453,7 +453,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
83501 */
83502 void __stack_chk_fail(void)
83503 {
83504- panic("stack-protector: Kernel stack is corrupted in: %p\n",
83505+ dump_stack();
83506+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
83507 __builtin_return_address(0));
83508 }
83509 EXPORT_SYMBOL(__stack_chk_fail);
83510diff --git a/kernel/pid.c b/kernel/pid.c
83511index 0db3e79..95b9dc2 100644
83512--- a/kernel/pid.c
83513+++ b/kernel/pid.c
83514@@ -33,6 +33,7 @@
83515 #include <linux/rculist.h>
83516 #include <linux/bootmem.h>
83517 #include <linux/hash.h>
83518+#include <linux/security.h>
83519 #include <linux/pid_namespace.h>
83520 #include <linux/init_task.h>
83521 #include <linux/syscalls.h>
83522@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
83523
83524 int pid_max = PID_MAX_DEFAULT;
83525
83526-#define RESERVED_PIDS 300
83527+#define RESERVED_PIDS 500
83528
83529 int pid_max_min = RESERVED_PIDS + 1;
83530 int pid_max_max = PID_MAX_LIMIT;
83531@@ -442,10 +443,18 @@ EXPORT_SYMBOL(pid_task);
83532 */
83533 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
83534 {
83535+ struct task_struct *task;
83536+
83537 rcu_lockdep_assert(rcu_read_lock_held(),
83538 "find_task_by_pid_ns() needs rcu_read_lock()"
83539 " protection");
83540- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83541+
83542+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83543+
83544+ if (gr_pid_is_chrooted(task))
83545+ return NULL;
83546+
83547+ return task;
83548 }
83549
83550 struct task_struct *find_task_by_vpid(pid_t vnr)
83551@@ -453,6 +462,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
83552 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
83553 }
83554
83555+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
83556+{
83557+ rcu_lockdep_assert(rcu_read_lock_held(),
83558+ "find_task_by_pid_ns() needs rcu_read_lock()"
83559+ " protection");
83560+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
83561+}
83562+
83563 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
83564 {
83565 struct pid *pid;
83566diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
83567index 6917e8e..9909aeb 100644
83568--- a/kernel/pid_namespace.c
83569+++ b/kernel/pid_namespace.c
83570@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
83571 void __user *buffer, size_t *lenp, loff_t *ppos)
83572 {
83573 struct pid_namespace *pid_ns = task_active_pid_ns(current);
83574- struct ctl_table tmp = *table;
83575+ ctl_table_no_const tmp = *table;
83576
83577 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
83578 return -EPERM;
83579diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
83580index 42670e9..8719c2f 100644
83581--- a/kernel/posix-cpu-timers.c
83582+++ b/kernel/posix-cpu-timers.c
83583@@ -1636,14 +1636,14 @@ struct k_clock clock_posix_cpu = {
83584
83585 static __init int init_posix_cpu_timers(void)
83586 {
83587- struct k_clock process = {
83588+ static struct k_clock process = {
83589 .clock_getres = process_cpu_clock_getres,
83590 .clock_get = process_cpu_clock_get,
83591 .timer_create = process_cpu_timer_create,
83592 .nsleep = process_cpu_nsleep,
83593 .nsleep_restart = process_cpu_nsleep_restart,
83594 };
83595- struct k_clock thread = {
83596+ static struct k_clock thread = {
83597 .clock_getres = thread_cpu_clock_getres,
83598 .clock_get = thread_cpu_clock_get,
83599 .timer_create = thread_cpu_timer_create,
83600diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
83601index 424c2d4..679242f 100644
83602--- a/kernel/posix-timers.c
83603+++ b/kernel/posix-timers.c
83604@@ -43,6 +43,7 @@
83605 #include <linux/hash.h>
83606 #include <linux/posix-clock.h>
83607 #include <linux/posix-timers.h>
83608+#include <linux/grsecurity.h>
83609 #include <linux/syscalls.h>
83610 #include <linux/wait.h>
83611 #include <linux/workqueue.h>
83612@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
83613 * which we beg off on and pass to do_sys_settimeofday().
83614 */
83615
83616-static struct k_clock posix_clocks[MAX_CLOCKS];
83617+static struct k_clock *posix_clocks[MAX_CLOCKS];
83618
83619 /*
83620 * These ones are defined below.
83621@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
83622 */
83623 static __init int init_posix_timers(void)
83624 {
83625- struct k_clock clock_realtime = {
83626+ static struct k_clock clock_realtime = {
83627 .clock_getres = hrtimer_get_res,
83628 .clock_get = posix_clock_realtime_get,
83629 .clock_set = posix_clock_realtime_set,
83630@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
83631 .timer_get = common_timer_get,
83632 .timer_del = common_timer_del,
83633 };
83634- struct k_clock clock_monotonic = {
83635+ static struct k_clock clock_monotonic = {
83636 .clock_getres = hrtimer_get_res,
83637 .clock_get = posix_ktime_get_ts,
83638 .nsleep = common_nsleep,
83639@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
83640 .timer_get = common_timer_get,
83641 .timer_del = common_timer_del,
83642 };
83643- struct k_clock clock_monotonic_raw = {
83644+ static struct k_clock clock_monotonic_raw = {
83645 .clock_getres = hrtimer_get_res,
83646 .clock_get = posix_get_monotonic_raw,
83647 };
83648- struct k_clock clock_realtime_coarse = {
83649+ static struct k_clock clock_realtime_coarse = {
83650 .clock_getres = posix_get_coarse_res,
83651 .clock_get = posix_get_realtime_coarse,
83652 };
83653- struct k_clock clock_monotonic_coarse = {
83654+ static struct k_clock clock_monotonic_coarse = {
83655 .clock_getres = posix_get_coarse_res,
83656 .clock_get = posix_get_monotonic_coarse,
83657 };
83658- struct k_clock clock_tai = {
83659+ static struct k_clock clock_tai = {
83660 .clock_getres = hrtimer_get_res,
83661 .clock_get = posix_get_tai,
83662 .nsleep = common_nsleep,
83663@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
83664 .timer_get = common_timer_get,
83665 .timer_del = common_timer_del,
83666 };
83667- struct k_clock clock_boottime = {
83668+ static struct k_clock clock_boottime = {
83669 .clock_getres = hrtimer_get_res,
83670 .clock_get = posix_get_boottime,
83671 .nsleep = common_nsleep,
83672@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
83673 return;
83674 }
83675
83676- posix_clocks[clock_id] = *new_clock;
83677+ posix_clocks[clock_id] = new_clock;
83678 }
83679 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
83680
83681@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
83682 return (id & CLOCKFD_MASK) == CLOCKFD ?
83683 &clock_posix_dynamic : &clock_posix_cpu;
83684
83685- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
83686+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
83687 return NULL;
83688- return &posix_clocks[id];
83689+ return posix_clocks[id];
83690 }
83691
83692 static int common_timer_create(struct k_itimer *new_timer)
83693@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
83694 struct k_clock *kc = clockid_to_kclock(which_clock);
83695 struct k_itimer *new_timer;
83696 int error, new_timer_id;
83697- sigevent_t event;
83698+ sigevent_t event = { };
83699 int it_id_set = IT_ID_NOT_SET;
83700
83701 if (!kc)
83702@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
83703 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
83704 return -EFAULT;
83705
83706+ /* only the CLOCK_REALTIME clock can be set, all other clocks
83707+ have their clock_set fptr set to a nosettime dummy function
83708+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
83709+ call common_clock_set, which calls do_sys_settimeofday, which
83710+ we hook
83711+ */
83712+
83713 return kc->clock_set(which_clock, &new_tp);
83714 }
83715
83716diff --git a/kernel/power/process.c b/kernel/power/process.c
83717index 98088e0..aaf95c0 100644
83718--- a/kernel/power/process.c
83719+++ b/kernel/power/process.c
83720@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
83721 u64 elapsed_csecs64;
83722 unsigned int elapsed_csecs;
83723 bool wakeup = false;
83724+ bool timedout = false;
83725
83726 do_gettimeofday(&start);
83727
83728@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
83729
83730 while (true) {
83731 todo = 0;
83732+ if (time_after(jiffies, end_time))
83733+ timedout = true;
83734 read_lock(&tasklist_lock);
83735 do_each_thread(g, p) {
83736 if (p == current || !freeze_task(p))
83737 continue;
83738
83739- if (!freezer_should_skip(p))
83740+ if (!freezer_should_skip(p)) {
83741 todo++;
83742+ if (timedout) {
83743+ printk(KERN_ERR "Task refusing to freeze:\n");
83744+ sched_show_task(p);
83745+ }
83746+ }
83747 } while_each_thread(g, p);
83748 read_unlock(&tasklist_lock);
83749
83750@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
83751 todo += wq_busy;
83752 }
83753
83754- if (!todo || time_after(jiffies, end_time))
83755+ if (!todo || timedout)
83756 break;
83757
83758 if (pm_wakeup_pending()) {
83759diff --git a/kernel/printk.c b/kernel/printk.c
83760index d37d45c..ab918b3 100644
83761--- a/kernel/printk.c
83762+++ b/kernel/printk.c
83763@@ -390,6 +390,11 @@ static int check_syslog_permissions(int type, bool from_file)
83764 if (from_file && type != SYSLOG_ACTION_OPEN)
83765 return 0;
83766
83767+#ifdef CONFIG_GRKERNSEC_DMESG
83768+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
83769+ return -EPERM;
83770+#endif
83771+
83772 if (syslog_action_restricted(type)) {
83773 if (capable(CAP_SYSLOG))
83774 return 0;
83775diff --git a/kernel/profile.c b/kernel/profile.c
83776index 0bf4007..6234708 100644
83777--- a/kernel/profile.c
83778+++ b/kernel/profile.c
83779@@ -37,7 +37,7 @@ struct profile_hit {
83780 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
83781 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
83782
83783-static atomic_t *prof_buffer;
83784+static atomic_unchecked_t *prof_buffer;
83785 static unsigned long prof_len, prof_shift;
83786
83787 int prof_on __read_mostly;
83788@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
83789 hits[i].pc = 0;
83790 continue;
83791 }
83792- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83793+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83794 hits[i].hits = hits[i].pc = 0;
83795 }
83796 }
83797@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83798 * Add the current hit(s) and flush the write-queue out
83799 * to the global buffer:
83800 */
83801- atomic_add(nr_hits, &prof_buffer[pc]);
83802+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
83803 for (i = 0; i < NR_PROFILE_HIT; ++i) {
83804- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83805+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83806 hits[i].pc = hits[i].hits = 0;
83807 }
83808 out:
83809@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83810 {
83811 unsigned long pc;
83812 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
83813- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83814+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83815 }
83816 #endif /* !CONFIG_SMP */
83817
83818@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
83819 return -EFAULT;
83820 buf++; p++; count--; read++;
83821 }
83822- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
83823+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
83824 if (copy_to_user(buf, (void *)pnt, count))
83825 return -EFAULT;
83826 read += count;
83827@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
83828 }
83829 #endif
83830 profile_discard_flip_buffers();
83831- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
83832+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
83833 return count;
83834 }
83835
83836diff --git a/kernel/ptrace.c b/kernel/ptrace.c
83837index 335a7ae..3bbbceb 100644
83838--- a/kernel/ptrace.c
83839+++ b/kernel/ptrace.c
83840@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
83841 if (seize)
83842 flags |= PT_SEIZED;
83843 rcu_read_lock();
83844- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83845+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83846 flags |= PT_PTRACE_CAP;
83847 rcu_read_unlock();
83848 task->ptrace = flags;
83849@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
83850 break;
83851 return -EIO;
83852 }
83853- if (copy_to_user(dst, buf, retval))
83854+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
83855 return -EFAULT;
83856 copied += retval;
83857 src += retval;
83858@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
83859 bool seized = child->ptrace & PT_SEIZED;
83860 int ret = -EIO;
83861 siginfo_t siginfo, *si;
83862- void __user *datavp = (void __user *) data;
83863+ void __user *datavp = (__force void __user *) data;
83864 unsigned long __user *datalp = datavp;
83865 unsigned long flags;
83866
83867@@ -1011,14 +1011,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
83868 goto out;
83869 }
83870
83871+ if (gr_handle_ptrace(child, request)) {
83872+ ret = -EPERM;
83873+ goto out_put_task_struct;
83874+ }
83875+
83876 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83877 ret = ptrace_attach(child, request, addr, data);
83878 /*
83879 * Some architectures need to do book-keeping after
83880 * a ptrace attach.
83881 */
83882- if (!ret)
83883+ if (!ret) {
83884 arch_ptrace_attach(child);
83885+ gr_audit_ptrace(child);
83886+ }
83887 goto out_put_task_struct;
83888 }
83889
83890@@ -1046,7 +1053,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
83891 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
83892 if (copied != sizeof(tmp))
83893 return -EIO;
83894- return put_user(tmp, (unsigned long __user *)data);
83895+ return put_user(tmp, (__force unsigned long __user *)data);
83896 }
83897
83898 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
83899@@ -1140,7 +1147,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
83900 }
83901
83902 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83903- compat_long_t addr, compat_long_t data)
83904+ compat_ulong_t addr, compat_ulong_t data)
83905 {
83906 struct task_struct *child;
83907 long ret;
83908@@ -1156,14 +1163,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83909 goto out;
83910 }
83911
83912+ if (gr_handle_ptrace(child, request)) {
83913+ ret = -EPERM;
83914+ goto out_put_task_struct;
83915+ }
83916+
83917 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83918 ret = ptrace_attach(child, request, addr, data);
83919 /*
83920 * Some architectures need to do book-keeping after
83921 * a ptrace attach.
83922 */
83923- if (!ret)
83924+ if (!ret) {
83925 arch_ptrace_attach(child);
83926+ gr_audit_ptrace(child);
83927+ }
83928 goto out_put_task_struct;
83929 }
83930
83931diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
83932index 48ab703..07561d4 100644
83933--- a/kernel/rcupdate.c
83934+++ b/kernel/rcupdate.c
83935@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
83936 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
83937 */
83938 if (till_stall_check < 3) {
83939- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
83940+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
83941 till_stall_check = 3;
83942 } else if (till_stall_check > 300) {
83943- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
83944+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
83945 till_stall_check = 300;
83946 }
83947 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
83948diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
83949index a0714a5..2ab5e34 100644
83950--- a/kernel/rcutiny.c
83951+++ b/kernel/rcutiny.c
83952@@ -46,7 +46,7 @@
83953 struct rcu_ctrlblk;
83954 static void invoke_rcu_callbacks(void);
83955 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
83956-static void rcu_process_callbacks(struct softirq_action *unused);
83957+static void rcu_process_callbacks(void);
83958 static void __call_rcu(struct rcu_head *head,
83959 void (*func)(struct rcu_head *rcu),
83960 struct rcu_ctrlblk *rcp);
83961@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
83962 rcu_is_callbacks_kthread()));
83963 }
83964
83965-static void rcu_process_callbacks(struct softirq_action *unused)
83966+static void rcu_process_callbacks(void)
83967 {
83968 __rcu_process_callbacks(&rcu_sched_ctrlblk);
83969 __rcu_process_callbacks(&rcu_bh_ctrlblk);
83970diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
83971index 8a23300..4255818 100644
83972--- a/kernel/rcutiny_plugin.h
83973+++ b/kernel/rcutiny_plugin.h
83974@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
83975 have_rcu_kthread_work = morework;
83976 local_irq_restore(flags);
83977 if (work)
83978- rcu_process_callbacks(NULL);
83979+ rcu_process_callbacks();
83980 schedule_timeout_interruptible(1); /* Leave CPU for others. */
83981 }
83982
83983diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
83984index e1f3a8c..42c94a2 100644
83985--- a/kernel/rcutorture.c
83986+++ b/kernel/rcutorture.c
83987@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
83988 { 0 };
83989 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
83990 { 0 };
83991-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
83992-static atomic_t n_rcu_torture_alloc;
83993-static atomic_t n_rcu_torture_alloc_fail;
83994-static atomic_t n_rcu_torture_free;
83995-static atomic_t n_rcu_torture_mberror;
83996-static atomic_t n_rcu_torture_error;
83997+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
83998+static atomic_unchecked_t n_rcu_torture_alloc;
83999+static atomic_unchecked_t n_rcu_torture_alloc_fail;
84000+static atomic_unchecked_t n_rcu_torture_free;
84001+static atomic_unchecked_t n_rcu_torture_mberror;
84002+static atomic_unchecked_t n_rcu_torture_error;
84003 static long n_rcu_torture_barrier_error;
84004 static long n_rcu_torture_boost_ktrerror;
84005 static long n_rcu_torture_boost_rterror;
84006@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
84007
84008 spin_lock_bh(&rcu_torture_lock);
84009 if (list_empty(&rcu_torture_freelist)) {
84010- atomic_inc(&n_rcu_torture_alloc_fail);
84011+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
84012 spin_unlock_bh(&rcu_torture_lock);
84013 return NULL;
84014 }
84015- atomic_inc(&n_rcu_torture_alloc);
84016+ atomic_inc_unchecked(&n_rcu_torture_alloc);
84017 p = rcu_torture_freelist.next;
84018 list_del_init(p);
84019 spin_unlock_bh(&rcu_torture_lock);
84020@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
84021 static void
84022 rcu_torture_free(struct rcu_torture *p)
84023 {
84024- atomic_inc(&n_rcu_torture_free);
84025+ atomic_inc_unchecked(&n_rcu_torture_free);
84026 spin_lock_bh(&rcu_torture_lock);
84027 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
84028 spin_unlock_bh(&rcu_torture_lock);
84029@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
84030 i = rp->rtort_pipe_count;
84031 if (i > RCU_TORTURE_PIPE_LEN)
84032 i = RCU_TORTURE_PIPE_LEN;
84033- atomic_inc(&rcu_torture_wcount[i]);
84034+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84035 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
84036 rp->rtort_mbtest = 0;
84037 rcu_torture_free(rp);
84038@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
84039 i = rp->rtort_pipe_count;
84040 if (i > RCU_TORTURE_PIPE_LEN)
84041 i = RCU_TORTURE_PIPE_LEN;
84042- atomic_inc(&rcu_torture_wcount[i]);
84043+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84044 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
84045 rp->rtort_mbtest = 0;
84046 list_del(&rp->rtort_free);
84047@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
84048 i = old_rp->rtort_pipe_count;
84049 if (i > RCU_TORTURE_PIPE_LEN)
84050 i = RCU_TORTURE_PIPE_LEN;
84051- atomic_inc(&rcu_torture_wcount[i]);
84052+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
84053 old_rp->rtort_pipe_count++;
84054 cur_ops->deferred_free(old_rp);
84055 }
84056@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
84057 return;
84058 }
84059 if (p->rtort_mbtest == 0)
84060- atomic_inc(&n_rcu_torture_mberror);
84061+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84062 spin_lock(&rand_lock);
84063 cur_ops->read_delay(&rand);
84064 n_rcu_torture_timers++;
84065@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
84066 continue;
84067 }
84068 if (p->rtort_mbtest == 0)
84069- atomic_inc(&n_rcu_torture_mberror);
84070+ atomic_inc_unchecked(&n_rcu_torture_mberror);
84071 cur_ops->read_delay(&rand);
84072 preempt_disable();
84073 pipe_count = p->rtort_pipe_count;
84074@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
84075 rcu_torture_current,
84076 rcu_torture_current_version,
84077 list_empty(&rcu_torture_freelist),
84078- atomic_read(&n_rcu_torture_alloc),
84079- atomic_read(&n_rcu_torture_alloc_fail),
84080- atomic_read(&n_rcu_torture_free));
84081+ atomic_read_unchecked(&n_rcu_torture_alloc),
84082+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
84083+ atomic_read_unchecked(&n_rcu_torture_free));
84084 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
84085- atomic_read(&n_rcu_torture_mberror),
84086+ atomic_read_unchecked(&n_rcu_torture_mberror),
84087 n_rcu_torture_boost_ktrerror,
84088 n_rcu_torture_boost_rterror);
84089 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
84090@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
84091 n_barrier_attempts,
84092 n_rcu_torture_barrier_error);
84093 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
84094- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
84095+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
84096 n_rcu_torture_barrier_error != 0 ||
84097 n_rcu_torture_boost_ktrerror != 0 ||
84098 n_rcu_torture_boost_rterror != 0 ||
84099 n_rcu_torture_boost_failure != 0 ||
84100 i > 1) {
84101 cnt += sprintf(&page[cnt], "!!! ");
84102- atomic_inc(&n_rcu_torture_error);
84103+ atomic_inc_unchecked(&n_rcu_torture_error);
84104 WARN_ON_ONCE(1);
84105 }
84106 cnt += sprintf(&page[cnt], "Reader Pipe: ");
84107@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
84108 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
84109 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
84110 cnt += sprintf(&page[cnt], " %d",
84111- atomic_read(&rcu_torture_wcount[i]));
84112+ atomic_read_unchecked(&rcu_torture_wcount[i]));
84113 }
84114 cnt += sprintf(&page[cnt], "\n");
84115 if (cur_ops->stats)
84116@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
84117
84118 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
84119
84120- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84121+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
84122 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
84123 else if (n_online_successes != n_online_attempts ||
84124 n_offline_successes != n_offline_attempts)
84125@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
84126
84127 rcu_torture_current = NULL;
84128 rcu_torture_current_version = 0;
84129- atomic_set(&n_rcu_torture_alloc, 0);
84130- atomic_set(&n_rcu_torture_alloc_fail, 0);
84131- atomic_set(&n_rcu_torture_free, 0);
84132- atomic_set(&n_rcu_torture_mberror, 0);
84133- atomic_set(&n_rcu_torture_error, 0);
84134+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
84135+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
84136+ atomic_set_unchecked(&n_rcu_torture_free, 0);
84137+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
84138+ atomic_set_unchecked(&n_rcu_torture_error, 0);
84139 n_rcu_torture_barrier_error = 0;
84140 n_rcu_torture_boost_ktrerror = 0;
84141 n_rcu_torture_boost_rterror = 0;
84142 n_rcu_torture_boost_failure = 0;
84143 n_rcu_torture_boosts = 0;
84144 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
84145- atomic_set(&rcu_torture_wcount[i], 0);
84146+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
84147 for_each_possible_cpu(cpu) {
84148 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
84149 per_cpu(rcu_torture_count, cpu)[i] = 0;
84150diff --git a/kernel/rcutree.c b/kernel/rcutree.c
84151index 3538001..e379e0b 100644
84152--- a/kernel/rcutree.c
84153+++ b/kernel/rcutree.c
84154@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
84155 rcu_prepare_for_idle(smp_processor_id());
84156 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
84157 smp_mb__before_atomic_inc(); /* See above. */
84158- atomic_inc(&rdtp->dynticks);
84159+ atomic_inc_unchecked(&rdtp->dynticks);
84160 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
84161- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
84162+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
84163
84164 /*
84165 * It is illegal to enter an extended quiescent state while
84166@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
84167 int user)
84168 {
84169 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
84170- atomic_inc(&rdtp->dynticks);
84171+ atomic_inc_unchecked(&rdtp->dynticks);
84172 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
84173 smp_mb__after_atomic_inc(); /* See above. */
84174- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
84175+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84176 rcu_cleanup_after_idle(smp_processor_id());
84177 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
84178 if (!user && !is_idle_task(current)) {
84179@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
84180 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
84181
84182 if (rdtp->dynticks_nmi_nesting == 0 &&
84183- (atomic_read(&rdtp->dynticks) & 0x1))
84184+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
84185 return;
84186 rdtp->dynticks_nmi_nesting++;
84187 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
84188- atomic_inc(&rdtp->dynticks);
84189+ atomic_inc_unchecked(&rdtp->dynticks);
84190 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
84191 smp_mb__after_atomic_inc(); /* See above. */
84192- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
84193+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
84194 }
84195
84196 /**
84197@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
84198 return;
84199 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
84200 smp_mb__before_atomic_inc(); /* See above. */
84201- atomic_inc(&rdtp->dynticks);
84202+ atomic_inc_unchecked(&rdtp->dynticks);
84203 smp_mb__after_atomic_inc(); /* Force delay to next write. */
84204- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
84205+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
84206 }
84207
84208 /**
84209@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
84210 int ret;
84211
84212 preempt_disable();
84213- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84214+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84215 preempt_enable();
84216 return ret;
84217 }
84218@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
84219 */
84220 static int dyntick_save_progress_counter(struct rcu_data *rdp)
84221 {
84222- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
84223+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84224 return (rdp->dynticks_snap & 0x1) == 0;
84225 }
84226
84227@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
84228 unsigned int curr;
84229 unsigned int snap;
84230
84231- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
84232+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84233 snap = (unsigned int)rdp->dynticks_snap;
84234
84235 /*
84236@@ -1440,9 +1440,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
84237 rdp = this_cpu_ptr(rsp->rda);
84238 rcu_preempt_check_blocked_tasks(rnp);
84239 rnp->qsmask = rnp->qsmaskinit;
84240- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
84241+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
84242 WARN_ON_ONCE(rnp->completed != rsp->completed);
84243- ACCESS_ONCE(rnp->completed) = rsp->completed;
84244+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
84245 if (rnp == rdp->mynode)
84246 rcu_start_gp_per_cpu(rsp, rnp, rdp);
84247 rcu_preempt_boost_start_gp(rnp);
84248@@ -1524,7 +1524,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
84249 */
84250 rcu_for_each_node_breadth_first(rsp, rnp) {
84251 raw_spin_lock_irq(&rnp->lock);
84252- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
84253+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
84254 rdp = this_cpu_ptr(rsp->rda);
84255 if (rnp == rdp->mynode)
84256 __rcu_process_gp_end(rsp, rnp, rdp);
84257@@ -1855,7 +1855,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
84258 rsp->qlen += rdp->qlen;
84259 rdp->n_cbs_orphaned += rdp->qlen;
84260 rdp->qlen_lazy = 0;
84261- ACCESS_ONCE(rdp->qlen) = 0;
84262+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84263 }
84264
84265 /*
84266@@ -2101,7 +2101,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
84267 }
84268 smp_mb(); /* List handling before counting for rcu_barrier(). */
84269 rdp->qlen_lazy -= count_lazy;
84270- ACCESS_ONCE(rdp->qlen) -= count;
84271+ ACCESS_ONCE_RW(rdp->qlen) -= count;
84272 rdp->n_cbs_invoked += count;
84273
84274 /* Reinstate batch limit if we have worked down the excess. */
84275@@ -2295,7 +2295,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
84276 /*
84277 * Do RCU core processing for the current CPU.
84278 */
84279-static void rcu_process_callbacks(struct softirq_action *unused)
84280+static void rcu_process_callbacks(void)
84281 {
84282 struct rcu_state *rsp;
84283
84284@@ -2419,7 +2419,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84285 local_irq_restore(flags);
84286 return;
84287 }
84288- ACCESS_ONCE(rdp->qlen)++;
84289+ ACCESS_ONCE_RW(rdp->qlen)++;
84290 if (lazy)
84291 rdp->qlen_lazy++;
84292 else
84293@@ -2628,11 +2628,11 @@ void synchronize_sched_expedited(void)
84294 * counter wrap on a 32-bit system. Quite a few more CPUs would of
84295 * course be required on a 64-bit system.
84296 */
84297- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
84298+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
84299 (ulong)atomic_long_read(&rsp->expedited_done) +
84300 ULONG_MAX / 8)) {
84301 synchronize_sched();
84302- atomic_long_inc(&rsp->expedited_wrap);
84303+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
84304 return;
84305 }
84306
84307@@ -2640,7 +2640,7 @@ void synchronize_sched_expedited(void)
84308 * Take a ticket. Note that atomic_inc_return() implies a
84309 * full memory barrier.
84310 */
84311- snap = atomic_long_inc_return(&rsp->expedited_start);
84312+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
84313 firstsnap = snap;
84314 get_online_cpus();
84315 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
84316@@ -2653,14 +2653,14 @@ void synchronize_sched_expedited(void)
84317 synchronize_sched_expedited_cpu_stop,
84318 NULL) == -EAGAIN) {
84319 put_online_cpus();
84320- atomic_long_inc(&rsp->expedited_tryfail);
84321+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
84322
84323 /* Check to see if someone else did our work for us. */
84324 s = atomic_long_read(&rsp->expedited_done);
84325 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84326 /* ensure test happens before caller kfree */
84327 smp_mb__before_atomic_inc(); /* ^^^ */
84328- atomic_long_inc(&rsp->expedited_workdone1);
84329+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
84330 return;
84331 }
84332
84333@@ -2669,7 +2669,7 @@ void synchronize_sched_expedited(void)
84334 udelay(trycount * num_online_cpus());
84335 } else {
84336 wait_rcu_gp(call_rcu_sched);
84337- atomic_long_inc(&rsp->expedited_normal);
84338+ atomic_long_inc_unchecked(&rsp->expedited_normal);
84339 return;
84340 }
84341
84342@@ -2678,7 +2678,7 @@ void synchronize_sched_expedited(void)
84343 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84344 /* ensure test happens before caller kfree */
84345 smp_mb__before_atomic_inc(); /* ^^^ */
84346- atomic_long_inc(&rsp->expedited_workdone2);
84347+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
84348 return;
84349 }
84350
84351@@ -2690,10 +2690,10 @@ void synchronize_sched_expedited(void)
84352 * period works for us.
84353 */
84354 get_online_cpus();
84355- snap = atomic_long_read(&rsp->expedited_start);
84356+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
84357 smp_mb(); /* ensure read is before try_stop_cpus(). */
84358 }
84359- atomic_long_inc(&rsp->expedited_stoppedcpus);
84360+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
84361
84362 /*
84363 * Everyone up to our most recent fetch is covered by our grace
84364@@ -2702,16 +2702,16 @@ void synchronize_sched_expedited(void)
84365 * than we did already did their update.
84366 */
84367 do {
84368- atomic_long_inc(&rsp->expedited_done_tries);
84369+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
84370 s = atomic_long_read(&rsp->expedited_done);
84371 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
84372 /* ensure test happens before caller kfree */
84373 smp_mb__before_atomic_inc(); /* ^^^ */
84374- atomic_long_inc(&rsp->expedited_done_lost);
84375+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
84376 break;
84377 }
84378 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
84379- atomic_long_inc(&rsp->expedited_done_exit);
84380+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
84381
84382 put_online_cpus();
84383 }
84384@@ -2893,7 +2893,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84385 * ACCESS_ONCE() to prevent the compiler from speculating
84386 * the increment to precede the early-exit check.
84387 */
84388- ACCESS_ONCE(rsp->n_barrier_done)++;
84389+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84390 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
84391 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
84392 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
84393@@ -2943,7 +2943,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84394
84395 /* Increment ->n_barrier_done to prevent duplicate work. */
84396 smp_mb(); /* Keep increment after above mechanism. */
84397- ACCESS_ONCE(rsp->n_barrier_done)++;
84398+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84399 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
84400 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
84401 smp_mb(); /* Keep increment before caller's subsequent code. */
84402@@ -2988,10 +2988,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
84403 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
84404 init_callback_list(rdp);
84405 rdp->qlen_lazy = 0;
84406- ACCESS_ONCE(rdp->qlen) = 0;
84407+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84408 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
84409 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
84410- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
84411+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
84412 rdp->cpu = cpu;
84413 rdp->rsp = rsp;
84414 rcu_boot_init_nocb_percpu_data(rdp);
84415@@ -3024,8 +3024,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
84416 rdp->blimit = blimit;
84417 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
84418 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
84419- atomic_set(&rdp->dynticks->dynticks,
84420- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
84421+ atomic_set_unchecked(&rdp->dynticks->dynticks,
84422+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
84423 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
84424
84425 /* Add CPU to rcu_node bitmasks. */
84426@@ -3120,7 +3120,7 @@ static int __init rcu_spawn_gp_kthread(void)
84427 struct task_struct *t;
84428
84429 for_each_rcu_flavor(rsp) {
84430- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
84431+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
84432 BUG_ON(IS_ERR(t));
84433 rnp = rcu_get_root(rsp);
84434 raw_spin_lock_irqsave(&rnp->lock, flags);
84435diff --git a/kernel/rcutree.h b/kernel/rcutree.h
84436index 4df5034..5ee93f2 100644
84437--- a/kernel/rcutree.h
84438+++ b/kernel/rcutree.h
84439@@ -87,7 +87,7 @@ struct rcu_dynticks {
84440 long long dynticks_nesting; /* Track irq/process nesting level. */
84441 /* Process level is worth LLONG_MAX/2. */
84442 int dynticks_nmi_nesting; /* Track NMI nesting level. */
84443- atomic_t dynticks; /* Even value for idle, else odd. */
84444+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
84445 #ifdef CONFIG_RCU_FAST_NO_HZ
84446 bool all_lazy; /* Are all CPU's CBs lazy? */
84447 unsigned long nonlazy_posted;
84448@@ -414,17 +414,17 @@ struct rcu_state {
84449 /* _rcu_barrier(). */
84450 /* End of fields guarded by barrier_mutex. */
84451
84452- atomic_long_t expedited_start; /* Starting ticket. */
84453- atomic_long_t expedited_done; /* Done ticket. */
84454- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
84455- atomic_long_t expedited_tryfail; /* # acquisition failures. */
84456- atomic_long_t expedited_workdone1; /* # done by others #1. */
84457- atomic_long_t expedited_workdone2; /* # done by others #2. */
84458- atomic_long_t expedited_normal; /* # fallbacks to normal. */
84459- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
84460- atomic_long_t expedited_done_tries; /* # tries to update _done. */
84461- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
84462- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
84463+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
84464+ atomic_long_t expedited_done; /* Done ticket. */
84465+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
84466+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
84467+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
84468+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
84469+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
84470+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
84471+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
84472+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
84473+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
84474
84475 unsigned long jiffies_force_qs; /* Time at which to invoke */
84476 /* force_quiescent_state(). */
84477diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
84478index 3db5a37..b395fb35 100644
84479--- a/kernel/rcutree_plugin.h
84480+++ b/kernel/rcutree_plugin.h
84481@@ -903,7 +903,7 @@ void synchronize_rcu_expedited(void)
84482
84483 /* Clean up and exit. */
84484 smp_mb(); /* ensure expedited GP seen before counter increment. */
84485- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
84486+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
84487 unlock_mb_ret:
84488 mutex_unlock(&sync_rcu_preempt_exp_mutex);
84489 mb_ret:
84490@@ -1451,7 +1451,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
84491 free_cpumask_var(cm);
84492 }
84493
84494-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
84495+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
84496 .store = &rcu_cpu_kthread_task,
84497 .thread_should_run = rcu_cpu_kthread_should_run,
84498 .thread_fn = rcu_cpu_kthread,
84499@@ -1916,7 +1916,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
84500 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
84501 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
84502 cpu, ticks_value, ticks_title,
84503- atomic_read(&rdtp->dynticks) & 0xfff,
84504+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
84505 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
84506 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
84507 fast_no_hz);
84508@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
84509
84510 /* Enqueue the callback on the nocb list and update counts. */
84511 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
84512- ACCESS_ONCE(*old_rhpp) = rhp;
84513+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
84514 atomic_long_add(rhcount, &rdp->nocb_q_count);
84515 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
84516
84517@@ -2219,12 +2219,12 @@ static int rcu_nocb_kthread(void *arg)
84518 * Extract queued callbacks, update counts, and wait
84519 * for a grace period to elapse.
84520 */
84521- ACCESS_ONCE(rdp->nocb_head) = NULL;
84522+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
84523 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
84524 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
84525 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
84526- ACCESS_ONCE(rdp->nocb_p_count) += c;
84527- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
84528+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
84529+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
84530 rcu_nocb_wait_gp(rdp);
84531
84532 /* Each pass through the following loop invokes a callback. */
84533@@ -2246,8 +2246,8 @@ static int rcu_nocb_kthread(void *arg)
84534 list = next;
84535 }
84536 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
84537- ACCESS_ONCE(rdp->nocb_p_count) -= c;
84538- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
84539+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
84540+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
84541 rdp->n_nocbs_invoked += c;
84542 }
84543 return 0;
84544@@ -2274,7 +2274,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
84545 t = kthread_run(rcu_nocb_kthread, rdp,
84546 "rcuo%c/%d", rsp->abbr, cpu);
84547 BUG_ON(IS_ERR(t));
84548- ACCESS_ONCE(rdp->nocb_kthread) = t;
84549+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
84550 }
84551 }
84552
84553diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
84554index cf6c174..a8f4b50 100644
84555--- a/kernel/rcutree_trace.c
84556+++ b/kernel/rcutree_trace.c
84557@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
84558 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
84559 rdp->passed_quiesce, rdp->qs_pending);
84560 seq_printf(m, " dt=%d/%llx/%d df=%lu",
84561- atomic_read(&rdp->dynticks->dynticks),
84562+ atomic_read_unchecked(&rdp->dynticks->dynticks),
84563 rdp->dynticks->dynticks_nesting,
84564 rdp->dynticks->dynticks_nmi_nesting,
84565 rdp->dynticks_fqs);
84566@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
84567 struct rcu_state *rsp = (struct rcu_state *)m->private;
84568
84569 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",
84570- atomic_long_read(&rsp->expedited_start),
84571+ atomic_long_read_unchecked(&rsp->expedited_start),
84572 atomic_long_read(&rsp->expedited_done),
84573- atomic_long_read(&rsp->expedited_wrap),
84574- atomic_long_read(&rsp->expedited_tryfail),
84575- atomic_long_read(&rsp->expedited_workdone1),
84576- atomic_long_read(&rsp->expedited_workdone2),
84577- atomic_long_read(&rsp->expedited_normal),
84578- atomic_long_read(&rsp->expedited_stoppedcpus),
84579- atomic_long_read(&rsp->expedited_done_tries),
84580- atomic_long_read(&rsp->expedited_done_lost),
84581- atomic_long_read(&rsp->expedited_done_exit));
84582+ atomic_long_read_unchecked(&rsp->expedited_wrap),
84583+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
84584+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
84585+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
84586+ atomic_long_read_unchecked(&rsp->expedited_normal),
84587+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
84588+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
84589+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
84590+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
84591 return 0;
84592 }
84593
84594diff --git a/kernel/resource.c b/kernel/resource.c
84595index d738698..5f8e60a 100644
84596--- a/kernel/resource.c
84597+++ b/kernel/resource.c
84598@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
84599
84600 static int __init ioresources_init(void)
84601 {
84602+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84603+#ifdef CONFIG_GRKERNSEC_PROC_USER
84604+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
84605+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
84606+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84607+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
84608+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
84609+#endif
84610+#else
84611 proc_create("ioports", 0, NULL, &proc_ioports_operations);
84612 proc_create("iomem", 0, NULL, &proc_iomem_operations);
84613+#endif
84614 return 0;
84615 }
84616 __initcall(ioresources_init);
84617diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
84618index 1d96dd0..994ff19 100644
84619--- a/kernel/rtmutex-tester.c
84620+++ b/kernel/rtmutex-tester.c
84621@@ -22,7 +22,7 @@
84622 #define MAX_RT_TEST_MUTEXES 8
84623
84624 static spinlock_t rttest_lock;
84625-static atomic_t rttest_event;
84626+static atomic_unchecked_t rttest_event;
84627
84628 struct test_thread_data {
84629 int opcode;
84630@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84631
84632 case RTTEST_LOCKCONT:
84633 td->mutexes[td->opdata] = 1;
84634- td->event = atomic_add_return(1, &rttest_event);
84635+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84636 return 0;
84637
84638 case RTTEST_RESET:
84639@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84640 return 0;
84641
84642 case RTTEST_RESETEVENT:
84643- atomic_set(&rttest_event, 0);
84644+ atomic_set_unchecked(&rttest_event, 0);
84645 return 0;
84646
84647 default:
84648@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84649 return ret;
84650
84651 td->mutexes[id] = 1;
84652- td->event = atomic_add_return(1, &rttest_event);
84653+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84654 rt_mutex_lock(&mutexes[id]);
84655- td->event = atomic_add_return(1, &rttest_event);
84656+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84657 td->mutexes[id] = 4;
84658 return 0;
84659
84660@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84661 return ret;
84662
84663 td->mutexes[id] = 1;
84664- td->event = atomic_add_return(1, &rttest_event);
84665+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84666 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
84667- td->event = atomic_add_return(1, &rttest_event);
84668+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84669 td->mutexes[id] = ret ? 0 : 4;
84670 return ret ? -EINTR : 0;
84671
84672@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84673 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
84674 return ret;
84675
84676- td->event = atomic_add_return(1, &rttest_event);
84677+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84678 rt_mutex_unlock(&mutexes[id]);
84679- td->event = atomic_add_return(1, &rttest_event);
84680+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84681 td->mutexes[id] = 0;
84682 return 0;
84683
84684@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84685 break;
84686
84687 td->mutexes[dat] = 2;
84688- td->event = atomic_add_return(1, &rttest_event);
84689+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84690 break;
84691
84692 default:
84693@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84694 return;
84695
84696 td->mutexes[dat] = 3;
84697- td->event = atomic_add_return(1, &rttest_event);
84698+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84699 break;
84700
84701 case RTTEST_LOCKNOWAIT:
84702@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84703 return;
84704
84705 td->mutexes[dat] = 1;
84706- td->event = atomic_add_return(1, &rttest_event);
84707+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84708 return;
84709
84710 default:
84711diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
84712index 64de5f8..7735e12 100644
84713--- a/kernel/sched/auto_group.c
84714+++ b/kernel/sched/auto_group.c
84715@@ -11,7 +11,7 @@
84716
84717 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
84718 static struct autogroup autogroup_default;
84719-static atomic_t autogroup_seq_nr;
84720+static atomic_unchecked_t autogroup_seq_nr;
84721
84722 void __init autogroup_init(struct task_struct *init_task)
84723 {
84724@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
84725
84726 kref_init(&ag->kref);
84727 init_rwsem(&ag->lock);
84728- ag->id = atomic_inc_return(&autogroup_seq_nr);
84729+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
84730 ag->tg = tg;
84731 #ifdef CONFIG_RT_GROUP_SCHED
84732 /*
84733diff --git a/kernel/sched/core.c b/kernel/sched/core.c
84734index e8b3350..d83d44e 100644
84735--- a/kernel/sched/core.c
84736+++ b/kernel/sched/core.c
84737@@ -3440,7 +3440,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
84738 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
84739 * positive (at least 1, or number of jiffies left till timeout) if completed.
84740 */
84741-long __sched
84742+long __sched __intentional_overflow(-1)
84743 wait_for_completion_interruptible_timeout(struct completion *x,
84744 unsigned long timeout)
84745 {
84746@@ -3457,7 +3457,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
84747 *
84748 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
84749 */
84750-int __sched wait_for_completion_killable(struct completion *x)
84751+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
84752 {
84753 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
84754 if (t == -ERESTARTSYS)
84755@@ -3478,7 +3478,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
84756 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
84757 * positive (at least 1, or number of jiffies left till timeout) if completed.
84758 */
84759-long __sched
84760+long __sched __intentional_overflow(-1)
84761 wait_for_completion_killable_timeout(struct completion *x,
84762 unsigned long timeout)
84763 {
84764@@ -3704,6 +3704,8 @@ int can_nice(const struct task_struct *p, const int nice)
84765 /* convert nice value [19,-20] to rlimit style value [1,40] */
84766 int nice_rlim = 20 - nice;
84767
84768+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
84769+
84770 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
84771 capable(CAP_SYS_NICE));
84772 }
84773@@ -3737,7 +3739,8 @@ SYSCALL_DEFINE1(nice, int, increment)
84774 if (nice > 19)
84775 nice = 19;
84776
84777- if (increment < 0 && !can_nice(current, nice))
84778+ if (increment < 0 && (!can_nice(current, nice) ||
84779+ gr_handle_chroot_nice()))
84780 return -EPERM;
84781
84782 retval = security_task_setnice(current, nice);
84783@@ -3891,6 +3894,7 @@ recheck:
84784 unsigned long rlim_rtprio =
84785 task_rlimit(p, RLIMIT_RTPRIO);
84786
84787+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
84788 /* can't set/change the rt policy */
84789 if (policy != p->policy && !rlim_rtprio)
84790 return -EPERM;
84791@@ -4988,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
84792
84793 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
84794
84795-static struct ctl_table sd_ctl_dir[] = {
84796+static ctl_table_no_const sd_ctl_dir[] __read_only = {
84797 {
84798 .procname = "sched_domain",
84799 .mode = 0555,
84800@@ -5005,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
84801 {}
84802 };
84803
84804-static struct ctl_table *sd_alloc_ctl_entry(int n)
84805+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
84806 {
84807- struct ctl_table *entry =
84808+ ctl_table_no_const *entry =
84809 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
84810
84811 return entry;
84812 }
84813
84814-static void sd_free_ctl_entry(struct ctl_table **tablep)
84815+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
84816 {
84817- struct ctl_table *entry;
84818+ ctl_table_no_const *entry;
84819
84820 /*
84821 * In the intermediate directories, both the child directory and
84822@@ -5023,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
84823 * will always be set. In the lowest directory the names are
84824 * static strings and all have proc handlers.
84825 */
84826- for (entry = *tablep; entry->mode; entry++) {
84827- if (entry->child)
84828- sd_free_ctl_entry(&entry->child);
84829+ for (entry = tablep; entry->mode; entry++) {
84830+ if (entry->child) {
84831+ sd_free_ctl_entry(entry->child);
84832+ pax_open_kernel();
84833+ entry->child = NULL;
84834+ pax_close_kernel();
84835+ }
84836 if (entry->proc_handler == NULL)
84837 kfree(entry->procname);
84838 }
84839
84840- kfree(*tablep);
84841- *tablep = NULL;
84842+ kfree(tablep);
84843 }
84844
84845 static int min_load_idx = 0;
84846 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
84847
84848 static void
84849-set_table_entry(struct ctl_table *entry,
84850+set_table_entry(ctl_table_no_const *entry,
84851 const char *procname, void *data, int maxlen,
84852 umode_t mode, proc_handler *proc_handler,
84853 bool load_idx)
84854@@ -5058,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
84855 static struct ctl_table *
84856 sd_alloc_ctl_domain_table(struct sched_domain *sd)
84857 {
84858- struct ctl_table *table = sd_alloc_ctl_entry(13);
84859+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
84860
84861 if (table == NULL)
84862 return NULL;
84863@@ -5093,9 +5100,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
84864 return table;
84865 }
84866
84867-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
84868+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
84869 {
84870- struct ctl_table *entry, *table;
84871+ ctl_table_no_const *entry, *table;
84872 struct sched_domain *sd;
84873 int domain_num = 0, i;
84874 char buf[32];
84875@@ -5122,11 +5129,13 @@ static struct ctl_table_header *sd_sysctl_header;
84876 static void register_sched_domain_sysctl(void)
84877 {
84878 int i, cpu_num = num_possible_cpus();
84879- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
84880+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
84881 char buf[32];
84882
84883 WARN_ON(sd_ctl_dir[0].child);
84884+ pax_open_kernel();
84885 sd_ctl_dir[0].child = entry;
84886+ pax_close_kernel();
84887
84888 if (entry == NULL)
84889 return;
84890@@ -5149,8 +5158,12 @@ static void unregister_sched_domain_sysctl(void)
84891 if (sd_sysctl_header)
84892 unregister_sysctl_table(sd_sysctl_header);
84893 sd_sysctl_header = NULL;
84894- if (sd_ctl_dir[0].child)
84895- sd_free_ctl_entry(&sd_ctl_dir[0].child);
84896+ if (sd_ctl_dir[0].child) {
84897+ sd_free_ctl_entry(sd_ctl_dir[0].child);
84898+ pax_open_kernel();
84899+ sd_ctl_dir[0].child = NULL;
84900+ pax_close_kernel();
84901+ }
84902 }
84903 #else
84904 static void register_sched_domain_sysctl(void)
84905@@ -5249,7 +5262,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
84906 * happens before everything else. This has to be lower priority than
84907 * the notifier in the perf_event subsystem, though.
84908 */
84909-static struct notifier_block __cpuinitdata migration_notifier = {
84910+static struct notifier_block migration_notifier = {
84911 .notifier_call = migration_call,
84912 .priority = CPU_PRI_MIGRATION,
84913 };
84914diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
84915index 03b73be..9422b9f 100644
84916--- a/kernel/sched/fair.c
84917+++ b/kernel/sched/fair.c
84918@@ -831,7 +831,7 @@ void task_numa_fault(int node, int pages, bool migrated)
84919
84920 static void reset_ptenuma_scan(struct task_struct *p)
84921 {
84922- ACCESS_ONCE(p->mm->numa_scan_seq)++;
84923+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
84924 p->mm->numa_scan_offset = 0;
84925 }
84926
84927@@ -5687,7 +5687,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
84928 * run_rebalance_domains is triggered when needed from the scheduler tick.
84929 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
84930 */
84931-static void run_rebalance_domains(struct softirq_action *h)
84932+static void run_rebalance_domains(void)
84933 {
84934 int this_cpu = smp_processor_id();
84935 struct rq *this_rq = cpu_rq(this_cpu);
84936diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
84937index ce39224d..0e09343 100644
84938--- a/kernel/sched/sched.h
84939+++ b/kernel/sched/sched.h
84940@@ -1009,7 +1009,7 @@ struct sched_class {
84941 #ifdef CONFIG_FAIR_GROUP_SCHED
84942 void (*task_move_group) (struct task_struct *p, int on_rq);
84943 #endif
84944-};
84945+} __do_const;
84946
84947 #define sched_class_highest (&stop_sched_class)
84948 #define for_each_class(class) \
84949diff --git a/kernel/signal.c b/kernel/signal.c
84950index 113411b..20d0a99 100644
84951--- a/kernel/signal.c
84952+++ b/kernel/signal.c
84953@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
84954
84955 int print_fatal_signals __read_mostly;
84956
84957-static void __user *sig_handler(struct task_struct *t, int sig)
84958+static __sighandler_t sig_handler(struct task_struct *t, int sig)
84959 {
84960 return t->sighand->action[sig - 1].sa.sa_handler;
84961 }
84962
84963-static int sig_handler_ignored(void __user *handler, int sig)
84964+static int sig_handler_ignored(__sighandler_t handler, int sig)
84965 {
84966 /* Is it explicitly or implicitly ignored? */
84967 return handler == SIG_IGN ||
84968@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
84969
84970 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
84971 {
84972- void __user *handler;
84973+ __sighandler_t handler;
84974
84975 handler = sig_handler(t, sig);
84976
84977@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
84978 atomic_inc(&user->sigpending);
84979 rcu_read_unlock();
84980
84981+ if (!override_rlimit)
84982+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
84983+
84984 if (override_rlimit ||
84985 atomic_read(&user->sigpending) <=
84986 task_rlimit(t, RLIMIT_SIGPENDING)) {
84987@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
84988
84989 int unhandled_signal(struct task_struct *tsk, int sig)
84990 {
84991- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
84992+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
84993 if (is_global_init(tsk))
84994 return 1;
84995 if (handler != SIG_IGN && handler != SIG_DFL)
84996@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
84997 }
84998 }
84999
85000+ /* allow glibc communication via tgkill to other threads in our
85001+ thread group */
85002+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
85003+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
85004+ && gr_handle_signal(t, sig))
85005+ return -EPERM;
85006+
85007 return security_task_kill(t, info, sig, 0);
85008 }
85009
85010@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85011 return send_signal(sig, info, p, 1);
85012 }
85013
85014-static int
85015+int
85016 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85017 {
85018 return send_signal(sig, info, t, 0);
85019@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85020 unsigned long int flags;
85021 int ret, blocked, ignored;
85022 struct k_sigaction *action;
85023+ int is_unhandled = 0;
85024
85025 spin_lock_irqsave(&t->sighand->siglock, flags);
85026 action = &t->sighand->action[sig-1];
85027@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
85028 }
85029 if (action->sa.sa_handler == SIG_DFL)
85030 t->signal->flags &= ~SIGNAL_UNKILLABLE;
85031+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
85032+ is_unhandled = 1;
85033 ret = specific_send_sig_info(sig, info, t);
85034 spin_unlock_irqrestore(&t->sighand->siglock, flags);
85035
85036+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
85037+ normal operation */
85038+ if (is_unhandled) {
85039+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
85040+ gr_handle_crash(t, sig);
85041+ }
85042+
85043 return ret;
85044 }
85045
85046@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
85047 ret = check_kill_permission(sig, info, p);
85048 rcu_read_unlock();
85049
85050- if (!ret && sig)
85051+ if (!ret && sig) {
85052 ret = do_send_sig_info(sig, info, p, true);
85053+ if (!ret)
85054+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
85055+ }
85056
85057 return ret;
85058 }
85059@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
85060 int error = -ESRCH;
85061
85062 rcu_read_lock();
85063- p = find_task_by_vpid(pid);
85064+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
85065+ /* allow glibc communication via tgkill to other threads in our
85066+ thread group */
85067+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
85068+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
85069+ p = find_task_by_vpid_unrestricted(pid);
85070+ else
85071+#endif
85072+ p = find_task_by_vpid(pid);
85073 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
85074 error = check_kill_permission(sig, info, p);
85075 /*
85076@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
85077 __put_user(t->sas_ss_size, &uss->ss_size);
85078 }
85079
85080+#ifdef CONFIG_X86
85081+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
85082+{
85083+ struct task_struct *t = current;
85084+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
85085+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
85086+ put_user_ex(t->sas_ss_size, &uss->ss_size);
85087+}
85088+#endif
85089+
85090 #ifdef CONFIG_COMPAT
85091 COMPAT_SYSCALL_DEFINE2(sigaltstack,
85092 const compat_stack_t __user *, uss_ptr,
85093@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
85094 }
85095 seg = get_fs();
85096 set_fs(KERNEL_DS);
85097- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
85098- (stack_t __force __user *) &uoss,
85099+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
85100+ (stack_t __force_user *) &uoss,
85101 compat_user_stack_pointer());
85102 set_fs(seg);
85103 if (ret >= 0 && uoss_ptr) {
85104@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
85105 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
85106 __put_user(t->sas_ss_size, &uss->ss_size);
85107 }
85108+
85109+#ifdef CONFIG_X86
85110+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
85111+{
85112+ struct task_struct *t = current;
85113+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
85114+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
85115+ put_user_ex(t->sas_ss_size, &uss->ss_size);
85116+}
85117+#endif
85118 #endif
85119
85120 #ifdef __ARCH_WANT_SYS_SIGPENDING
85121diff --git a/kernel/smp.c b/kernel/smp.c
85122index 4dba0f7..fe9f773 100644
85123--- a/kernel/smp.c
85124+++ b/kernel/smp.c
85125@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
85126 return NOTIFY_OK;
85127 }
85128
85129-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
85130+static struct notifier_block hotplug_cfd_notifier = {
85131 .notifier_call = hotplug_cfd,
85132 };
85133
85134diff --git a/kernel/smpboot.c b/kernel/smpboot.c
85135index 02fc5c9..e54c335 100644
85136--- a/kernel/smpboot.c
85137+++ b/kernel/smpboot.c
85138@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
85139 }
85140 smpboot_unpark_thread(plug_thread, cpu);
85141 }
85142- list_add(&plug_thread->list, &hotplug_threads);
85143+ pax_list_add(&plug_thread->list, &hotplug_threads);
85144 out:
85145 mutex_unlock(&smpboot_threads_lock);
85146 return ret;
85147@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
85148 {
85149 get_online_cpus();
85150 mutex_lock(&smpboot_threads_lock);
85151- list_del(&plug_thread->list);
85152+ pax_list_del(&plug_thread->list);
85153 smpboot_destroy_threads(plug_thread);
85154 mutex_unlock(&smpboot_threads_lock);
85155 put_online_cpus();
85156diff --git a/kernel/softirq.c b/kernel/softirq.c
85157index 3d6833f..da6d93d 100644
85158--- a/kernel/softirq.c
85159+++ b/kernel/softirq.c
85160@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
85161 EXPORT_SYMBOL(irq_stat);
85162 #endif
85163
85164-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
85165+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
85166
85167 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
85168
85169-char *softirq_to_name[NR_SOFTIRQS] = {
85170+const char * const softirq_to_name[NR_SOFTIRQS] = {
85171 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
85172 "TASKLET", "SCHED", "HRTIMER", "RCU"
85173 };
85174@@ -250,7 +250,7 @@ restart:
85175 kstat_incr_softirqs_this_cpu(vec_nr);
85176
85177 trace_softirq_entry(vec_nr);
85178- h->action(h);
85179+ h->action();
85180 trace_softirq_exit(vec_nr);
85181 if (unlikely(prev_count != preempt_count())) {
85182 printk(KERN_ERR "huh, entered softirq %u %s %p"
85183@@ -405,7 +405,7 @@ void __raise_softirq_irqoff(unsigned int nr)
85184 or_softirq_pending(1UL << nr);
85185 }
85186
85187-void open_softirq(int nr, void (*action)(struct softirq_action *))
85188+void __init open_softirq(int nr, void (*action)(void))
85189 {
85190 softirq_vec[nr].action = action;
85191 }
85192@@ -461,7 +461,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
85193
85194 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
85195
85196-static void tasklet_action(struct softirq_action *a)
85197+static void tasklet_action(void)
85198 {
85199 struct tasklet_struct *list;
85200
85201@@ -496,7 +496,7 @@ static void tasklet_action(struct softirq_action *a)
85202 }
85203 }
85204
85205-static void tasklet_hi_action(struct softirq_action *a)
85206+static void tasklet_hi_action(void)
85207 {
85208 struct tasklet_struct *list;
85209
85210@@ -730,7 +730,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
85211 return NOTIFY_OK;
85212 }
85213
85214-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
85215+static struct notifier_block remote_softirq_cpu_notifier = {
85216 .notifier_call = remote_softirq_cpu_notify,
85217 };
85218
85219@@ -847,11 +847,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
85220 return NOTIFY_OK;
85221 }
85222
85223-static struct notifier_block __cpuinitdata cpu_nfb = {
85224+static struct notifier_block cpu_nfb = {
85225 .notifier_call = cpu_callback
85226 };
85227
85228-static struct smp_hotplug_thread softirq_threads = {
85229+static struct smp_hotplug_thread softirq_threads __read_only = {
85230 .store = &ksoftirqd,
85231 .thread_should_run = ksoftirqd_should_run,
85232 .thread_fn = run_ksoftirqd,
85233diff --git a/kernel/srcu.c b/kernel/srcu.c
85234index 01d5ccb..cdcbee6 100644
85235--- a/kernel/srcu.c
85236+++ b/kernel/srcu.c
85237@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
85238
85239 idx = ACCESS_ONCE(sp->completed) & 0x1;
85240 preempt_disable();
85241- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85242+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
85243 smp_mb(); /* B */ /* Avoid leaking the critical section. */
85244- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85245+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85246 preempt_enable();
85247 return idx;
85248 }
85249diff --git a/kernel/sys.c b/kernel/sys.c
85250index 2bbd9a7..0875671 100644
85251--- a/kernel/sys.c
85252+++ b/kernel/sys.c
85253@@ -163,6 +163,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
85254 error = -EACCES;
85255 goto out;
85256 }
85257+
85258+ if (gr_handle_chroot_setpriority(p, niceval)) {
85259+ error = -EACCES;
85260+ goto out;
85261+ }
85262+
85263 no_nice = security_task_setnice(p, niceval);
85264 if (no_nice) {
85265 error = no_nice;
85266@@ -626,6 +632,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
85267 goto error;
85268 }
85269
85270+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
85271+ goto error;
85272+
85273 if (rgid != (gid_t) -1 ||
85274 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
85275 new->sgid = new->egid;
85276@@ -661,6 +670,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
85277 old = current_cred();
85278
85279 retval = -EPERM;
85280+
85281+ if (gr_check_group_change(kgid, kgid, kgid))
85282+ goto error;
85283+
85284 if (nsown_capable(CAP_SETGID))
85285 new->gid = new->egid = new->sgid = new->fsgid = kgid;
85286 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
85287@@ -678,7 +691,7 @@ error:
85288 /*
85289 * change the user struct in a credentials set to match the new UID
85290 */
85291-static int set_user(struct cred *new)
85292+int set_user(struct cred *new)
85293 {
85294 struct user_struct *new_user;
85295
85296@@ -758,6 +771,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
85297 goto error;
85298 }
85299
85300+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
85301+ goto error;
85302+
85303 if (!uid_eq(new->uid, old->uid)) {
85304 retval = set_user(new);
85305 if (retval < 0)
85306@@ -808,6 +824,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
85307 old = current_cred();
85308
85309 retval = -EPERM;
85310+
85311+ if (gr_check_crash_uid(kuid))
85312+ goto error;
85313+ if (gr_check_user_change(kuid, kuid, kuid))
85314+ goto error;
85315+
85316 if (nsown_capable(CAP_SETUID)) {
85317 new->suid = new->uid = kuid;
85318 if (!uid_eq(kuid, old->uid)) {
85319@@ -877,6 +899,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
85320 goto error;
85321 }
85322
85323+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
85324+ goto error;
85325+
85326 if (ruid != (uid_t) -1) {
85327 new->uid = kruid;
85328 if (!uid_eq(kruid, old->uid)) {
85329@@ -959,6 +984,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
85330 goto error;
85331 }
85332
85333+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
85334+ goto error;
85335+
85336 if (rgid != (gid_t) -1)
85337 new->gid = krgid;
85338 if (egid != (gid_t) -1)
85339@@ -1020,12 +1048,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
85340 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
85341 nsown_capable(CAP_SETUID)) {
85342 if (!uid_eq(kuid, old->fsuid)) {
85343+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
85344+ goto error;
85345+
85346 new->fsuid = kuid;
85347 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
85348 goto change_okay;
85349 }
85350 }
85351
85352+error:
85353 abort_creds(new);
85354 return old_fsuid;
85355
85356@@ -1058,12 +1090,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
85357 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
85358 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
85359 nsown_capable(CAP_SETGID)) {
85360+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
85361+ goto error;
85362+
85363 if (!gid_eq(kgid, old->fsgid)) {
85364 new->fsgid = kgid;
85365 goto change_okay;
85366 }
85367 }
85368
85369+error:
85370 abort_creds(new);
85371 return old_fsgid;
85372
85373@@ -1432,19 +1468,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
85374 return -EFAULT;
85375
85376 down_read(&uts_sem);
85377- error = __copy_to_user(&name->sysname, &utsname()->sysname,
85378+ error = __copy_to_user(name->sysname, &utsname()->sysname,
85379 __OLD_UTS_LEN);
85380 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
85381- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
85382+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
85383 __OLD_UTS_LEN);
85384 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
85385- error |= __copy_to_user(&name->release, &utsname()->release,
85386+ error |= __copy_to_user(name->release, &utsname()->release,
85387 __OLD_UTS_LEN);
85388 error |= __put_user(0, name->release + __OLD_UTS_LEN);
85389- error |= __copy_to_user(&name->version, &utsname()->version,
85390+ error |= __copy_to_user(name->version, &utsname()->version,
85391 __OLD_UTS_LEN);
85392 error |= __put_user(0, name->version + __OLD_UTS_LEN);
85393- error |= __copy_to_user(&name->machine, &utsname()->machine,
85394+ error |= __copy_to_user(name->machine, &utsname()->machine,
85395 __OLD_UTS_LEN);
85396 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
85397 up_read(&uts_sem);
85398@@ -1646,6 +1682,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
85399 */
85400 new_rlim->rlim_cur = 1;
85401 }
85402+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
85403+ is changed to a lower value. Since tasks can be created by the same
85404+ user in between this limit change and an execve by this task, force
85405+ a recheck only for this task by setting PF_NPROC_EXCEEDED
85406+ */
85407+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
85408+ tsk->flags |= PF_NPROC_EXCEEDED;
85409 }
85410 if (!retval) {
85411 if (old_rlim)
85412diff --git a/kernel/sysctl.c b/kernel/sysctl.c
85413index 9edcf45..713c960 100644
85414--- a/kernel/sysctl.c
85415+++ b/kernel/sysctl.c
85416@@ -93,7 +93,6 @@
85417
85418
85419 #if defined(CONFIG_SYSCTL)
85420-
85421 /* External variables not in a header file. */
85422 extern int sysctl_overcommit_memory;
85423 extern int sysctl_overcommit_ratio;
85424@@ -119,18 +118,18 @@ extern int blk_iopoll_enabled;
85425
85426 /* Constants used for minimum and maximum */
85427 #ifdef CONFIG_LOCKUP_DETECTOR
85428-static int sixty = 60;
85429-static int neg_one = -1;
85430+static int sixty __read_only = 60;
85431 #endif
85432
85433-static int zero;
85434-static int __maybe_unused one = 1;
85435-static int __maybe_unused two = 2;
85436-static int __maybe_unused three = 3;
85437-static unsigned long one_ul = 1;
85438-static int one_hundred = 100;
85439+static int neg_one __read_only = -1;
85440+static int zero __read_only = 0;
85441+static int __maybe_unused one __read_only = 1;
85442+static int __maybe_unused two __read_only = 2;
85443+static int __maybe_unused three __read_only = 3;
85444+static unsigned long one_ul __read_only = 1;
85445+static int one_hundred __read_only = 100;
85446 #ifdef CONFIG_PRINTK
85447-static int ten_thousand = 10000;
85448+static int ten_thousand __read_only = 10000;
85449 #endif
85450
85451 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
85452@@ -177,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
85453 void __user *buffer, size_t *lenp, loff_t *ppos);
85454 #endif
85455
85456-#ifdef CONFIG_PRINTK
85457 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85458 void __user *buffer, size_t *lenp, loff_t *ppos);
85459-#endif
85460
85461 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
85462 void __user *buffer, size_t *lenp, loff_t *ppos);
85463@@ -211,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
85464
85465 #endif
85466
85467+extern struct ctl_table grsecurity_table[];
85468+
85469 static struct ctl_table kern_table[];
85470 static struct ctl_table vm_table[];
85471 static struct ctl_table fs_table[];
85472@@ -225,6 +224,20 @@ extern struct ctl_table epoll_table[];
85473 int sysctl_legacy_va_layout;
85474 #endif
85475
85476+#ifdef CONFIG_PAX_SOFTMODE
85477+static ctl_table pax_table[] = {
85478+ {
85479+ .procname = "softmode",
85480+ .data = &pax_softmode,
85481+ .maxlen = sizeof(unsigned int),
85482+ .mode = 0600,
85483+ .proc_handler = &proc_dointvec,
85484+ },
85485+
85486+ { }
85487+};
85488+#endif
85489+
85490 /* The default sysctl tables: */
85491
85492 static struct ctl_table sysctl_base_table[] = {
85493@@ -273,6 +286,22 @@ static int max_extfrag_threshold = 1000;
85494 #endif
85495
85496 static struct ctl_table kern_table[] = {
85497+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
85498+ {
85499+ .procname = "grsecurity",
85500+ .mode = 0500,
85501+ .child = grsecurity_table,
85502+ },
85503+#endif
85504+
85505+#ifdef CONFIG_PAX_SOFTMODE
85506+ {
85507+ .procname = "pax",
85508+ .mode = 0500,
85509+ .child = pax_table,
85510+ },
85511+#endif
85512+
85513 {
85514 .procname = "sched_child_runs_first",
85515 .data = &sysctl_sched_child_runs_first,
85516@@ -607,7 +636,7 @@ static struct ctl_table kern_table[] = {
85517 .data = &modprobe_path,
85518 .maxlen = KMOD_PATH_LEN,
85519 .mode = 0644,
85520- .proc_handler = proc_dostring,
85521+ .proc_handler = proc_dostring_modpriv,
85522 },
85523 {
85524 .procname = "modules_disabled",
85525@@ -774,16 +803,20 @@ static struct ctl_table kern_table[] = {
85526 .extra1 = &zero,
85527 .extra2 = &one,
85528 },
85529+#endif
85530 {
85531 .procname = "kptr_restrict",
85532 .data = &kptr_restrict,
85533 .maxlen = sizeof(int),
85534 .mode = 0644,
85535 .proc_handler = proc_dointvec_minmax_sysadmin,
85536+#ifdef CONFIG_GRKERNSEC_HIDESYM
85537+ .extra1 = &two,
85538+#else
85539 .extra1 = &zero,
85540+#endif
85541 .extra2 = &two,
85542 },
85543-#endif
85544 {
85545 .procname = "ngroups_max",
85546 .data = &ngroups_max,
85547@@ -1025,10 +1058,17 @@ static struct ctl_table kern_table[] = {
85548 */
85549 {
85550 .procname = "perf_event_paranoid",
85551- .data = &sysctl_perf_event_paranoid,
85552- .maxlen = sizeof(sysctl_perf_event_paranoid),
85553+ .data = &sysctl_perf_event_legitimately_concerned,
85554+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
85555 .mode = 0644,
85556- .proc_handler = proc_dointvec,
85557+ /* go ahead, be a hero */
85558+ .proc_handler = proc_dointvec_minmax_sysadmin,
85559+ .extra1 = &neg_one,
85560+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85561+ .extra2 = &three,
85562+#else
85563+ .extra2 = &two,
85564+#endif
85565 },
85566 {
85567 .procname = "perf_event_mlock_kb",
85568@@ -1282,6 +1322,13 @@ static struct ctl_table vm_table[] = {
85569 .proc_handler = proc_dointvec_minmax,
85570 .extra1 = &zero,
85571 },
85572+ {
85573+ .procname = "heap_stack_gap",
85574+ .data = &sysctl_heap_stack_gap,
85575+ .maxlen = sizeof(sysctl_heap_stack_gap),
85576+ .mode = 0644,
85577+ .proc_handler = proc_doulongvec_minmax,
85578+ },
85579 #else
85580 {
85581 .procname = "nr_trim_pages",
85582@@ -1746,6 +1793,16 @@ int proc_dostring(struct ctl_table *table, int write,
85583 buffer, lenp, ppos);
85584 }
85585
85586+int proc_dostring_modpriv(struct ctl_table *table, int write,
85587+ void __user *buffer, size_t *lenp, loff_t *ppos)
85588+{
85589+ if (write && !capable(CAP_SYS_MODULE))
85590+ return -EPERM;
85591+
85592+ return _proc_do_string(table->data, table->maxlen, write,
85593+ buffer, lenp, ppos);
85594+}
85595+
85596 static size_t proc_skip_spaces(char **buf)
85597 {
85598 size_t ret;
85599@@ -1851,6 +1908,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
85600 len = strlen(tmp);
85601 if (len > *size)
85602 len = *size;
85603+ if (len > sizeof(tmp))
85604+ len = sizeof(tmp);
85605 if (copy_to_user(*buf, tmp, len))
85606 return -EFAULT;
85607 *size -= len;
85608@@ -2015,7 +2074,7 @@ int proc_dointvec(struct ctl_table *table, int write,
85609 static int proc_taint(struct ctl_table *table, int write,
85610 void __user *buffer, size_t *lenp, loff_t *ppos)
85611 {
85612- struct ctl_table t;
85613+ ctl_table_no_const t;
85614 unsigned long tmptaint = get_taint();
85615 int err;
85616
85617@@ -2043,7 +2102,6 @@ static int proc_taint(struct ctl_table *table, int write,
85618 return err;
85619 }
85620
85621-#ifdef CONFIG_PRINTK
85622 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85623 void __user *buffer, size_t *lenp, loff_t *ppos)
85624 {
85625@@ -2052,7 +2110,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85626
85627 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
85628 }
85629-#endif
85630
85631 struct do_proc_dointvec_minmax_conv_param {
85632 int *min;
85633@@ -2199,8 +2256,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
85634 *i = val;
85635 } else {
85636 val = convdiv * (*i) / convmul;
85637- if (!first)
85638+ if (!first) {
85639 err = proc_put_char(&buffer, &left, '\t');
85640+ if (err)
85641+ break;
85642+ }
85643 err = proc_put_long(&buffer, &left, val, false);
85644 if (err)
85645 break;
85646@@ -2592,6 +2652,12 @@ int proc_dostring(struct ctl_table *table, int write,
85647 return -ENOSYS;
85648 }
85649
85650+int proc_dostring_modpriv(struct ctl_table *table, int write,
85651+ void __user *buffer, size_t *lenp, loff_t *ppos)
85652+{
85653+ return -ENOSYS;
85654+}
85655+
85656 int proc_dointvec(struct ctl_table *table, int write,
85657 void __user *buffer, size_t *lenp, loff_t *ppos)
85658 {
85659@@ -2648,5 +2714,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
85660 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
85661 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
85662 EXPORT_SYMBOL(proc_dostring);
85663+EXPORT_SYMBOL(proc_dostring_modpriv);
85664 EXPORT_SYMBOL(proc_doulongvec_minmax);
85665 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
85666diff --git a/kernel/taskstats.c b/kernel/taskstats.c
85667index 145bb4d..b2aa969 100644
85668--- a/kernel/taskstats.c
85669+++ b/kernel/taskstats.c
85670@@ -28,9 +28,12 @@
85671 #include <linux/fs.h>
85672 #include <linux/file.h>
85673 #include <linux/pid_namespace.h>
85674+#include <linux/grsecurity.h>
85675 #include <net/genetlink.h>
85676 #include <linux/atomic.h>
85677
85678+extern int gr_is_taskstats_denied(int pid);
85679+
85680 /*
85681 * Maximum length of a cpumask that can be specified in
85682 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
85683@@ -570,6 +573,9 @@ err:
85684
85685 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
85686 {
85687+ if (gr_is_taskstats_denied(current->pid))
85688+ return -EACCES;
85689+
85690 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
85691 return cmd_attr_register_cpumask(info);
85692 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
85693diff --git a/kernel/time.c b/kernel/time.c
85694index d3617db..c98bbe9 100644
85695--- a/kernel/time.c
85696+++ b/kernel/time.c
85697@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
85698 return error;
85699
85700 if (tz) {
85701+ /* we log in do_settimeofday called below, so don't log twice
85702+ */
85703+ if (!tv)
85704+ gr_log_timechange();
85705+
85706 sys_tz = *tz;
85707 update_vsyscall_tz();
85708 if (firsttime) {
85709@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
85710 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
85711 * value to a scaled second value.
85712 */
85713-unsigned long
85714+unsigned long __intentional_overflow(-1)
85715 timespec_to_jiffies(const struct timespec *value)
85716 {
85717 unsigned long sec = value->tv_sec;
85718diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
85719index f11d83b..d016d91 100644
85720--- a/kernel/time/alarmtimer.c
85721+++ b/kernel/time/alarmtimer.c
85722@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
85723 struct platform_device *pdev;
85724 int error = 0;
85725 int i;
85726- struct k_clock alarm_clock = {
85727+ static struct k_clock alarm_clock = {
85728 .clock_getres = alarm_clock_getres,
85729 .clock_get = alarm_clock_get,
85730 .timer_create = alarm_timer_create,
85731diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
85732index baeeb5c..c22704a 100644
85733--- a/kernel/time/timekeeping.c
85734+++ b/kernel/time/timekeeping.c
85735@@ -15,6 +15,7 @@
85736 #include <linux/init.h>
85737 #include <linux/mm.h>
85738 #include <linux/sched.h>
85739+#include <linux/grsecurity.h>
85740 #include <linux/syscore_ops.h>
85741 #include <linux/clocksource.h>
85742 #include <linux/jiffies.h>
85743@@ -495,6 +496,8 @@ int do_settimeofday(const struct timespec *tv)
85744 if (!timespec_valid_strict(tv))
85745 return -EINVAL;
85746
85747+ gr_log_timechange();
85748+
85749 raw_spin_lock_irqsave(&timekeeper_lock, flags);
85750 write_seqcount_begin(&timekeeper_seq);
85751
85752diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
85753index 3bdf283..cc68d83 100644
85754--- a/kernel/time/timer_list.c
85755+++ b/kernel/time/timer_list.c
85756@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
85757
85758 static void print_name_offset(struct seq_file *m, void *sym)
85759 {
85760+#ifdef CONFIG_GRKERNSEC_HIDESYM
85761+ SEQ_printf(m, "<%p>", NULL);
85762+#else
85763 char symname[KSYM_NAME_LEN];
85764
85765 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
85766 SEQ_printf(m, "<%pK>", sym);
85767 else
85768 SEQ_printf(m, "%s", symname);
85769+#endif
85770 }
85771
85772 static void
85773@@ -119,7 +123,11 @@ next_one:
85774 static void
85775 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
85776 {
85777+#ifdef CONFIG_GRKERNSEC_HIDESYM
85778+ SEQ_printf(m, " .base: %p\n", NULL);
85779+#else
85780 SEQ_printf(m, " .base: %pK\n", base);
85781+#endif
85782 SEQ_printf(m, " .index: %d\n",
85783 base->index);
85784 SEQ_printf(m, " .resolution: %Lu nsecs\n",
85785@@ -355,7 +363,11 @@ static int __init init_timer_list_procfs(void)
85786 {
85787 struct proc_dir_entry *pe;
85788
85789+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85790+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
85791+#else
85792 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
85793+#endif
85794 if (!pe)
85795 return -ENOMEM;
85796 return 0;
85797diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
85798index 0b537f2..40d6c20 100644
85799--- a/kernel/time/timer_stats.c
85800+++ b/kernel/time/timer_stats.c
85801@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
85802 static unsigned long nr_entries;
85803 static struct entry entries[MAX_ENTRIES];
85804
85805-static atomic_t overflow_count;
85806+static atomic_unchecked_t overflow_count;
85807
85808 /*
85809 * The entries are in a hash-table, for fast lookup:
85810@@ -140,7 +140,7 @@ static void reset_entries(void)
85811 nr_entries = 0;
85812 memset(entries, 0, sizeof(entries));
85813 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
85814- atomic_set(&overflow_count, 0);
85815+ atomic_set_unchecked(&overflow_count, 0);
85816 }
85817
85818 static struct entry *alloc_entry(void)
85819@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85820 if (likely(entry))
85821 entry->count++;
85822 else
85823- atomic_inc(&overflow_count);
85824+ atomic_inc_unchecked(&overflow_count);
85825
85826 out_unlock:
85827 raw_spin_unlock_irqrestore(lock, flags);
85828@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85829
85830 static void print_name_offset(struct seq_file *m, unsigned long addr)
85831 {
85832+#ifdef CONFIG_GRKERNSEC_HIDESYM
85833+ seq_printf(m, "<%p>", NULL);
85834+#else
85835 char symname[KSYM_NAME_LEN];
85836
85837 if (lookup_symbol_name(addr, symname) < 0)
85838- seq_printf(m, "<%p>", (void *)addr);
85839+ seq_printf(m, "<%pK>", (void *)addr);
85840 else
85841 seq_printf(m, "%s", symname);
85842+#endif
85843 }
85844
85845 static int tstats_show(struct seq_file *m, void *v)
85846@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
85847
85848 seq_puts(m, "Timer Stats Version: v0.2\n");
85849 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
85850- if (atomic_read(&overflow_count))
85851+ if (atomic_read_unchecked(&overflow_count))
85852 seq_printf(m, "Overflow: %d entries\n",
85853- atomic_read(&overflow_count));
85854+ atomic_read_unchecked(&overflow_count));
85855
85856 for (i = 0; i < nr_entries; i++) {
85857 entry = entries + i;
85858@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
85859 {
85860 struct proc_dir_entry *pe;
85861
85862+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85863+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
85864+#else
85865 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
85866+#endif
85867 if (!pe)
85868 return -ENOMEM;
85869 return 0;
85870diff --git a/kernel/timer.c b/kernel/timer.c
85871index 15bc1b4..32da49c 100644
85872--- a/kernel/timer.c
85873+++ b/kernel/timer.c
85874@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
85875 /*
85876 * This function runs timers and the timer-tq in bottom half context.
85877 */
85878-static void run_timer_softirq(struct softirq_action *h)
85879+static void run_timer_softirq(void)
85880 {
85881 struct tvec_base *base = __this_cpu_read(tvec_bases);
85882
85883@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
85884 *
85885 * In all cases the return value is guaranteed to be non-negative.
85886 */
85887-signed long __sched schedule_timeout(signed long timeout)
85888+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
85889 {
85890 struct timer_list timer;
85891 unsigned long expire;
85892@@ -1635,7 +1635,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
85893 return NOTIFY_OK;
85894 }
85895
85896-static struct notifier_block __cpuinitdata timers_nb = {
85897+static struct notifier_block timers_nb = {
85898 .notifier_call = timer_cpu_notify,
85899 };
85900
85901diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
85902index b8b8560..75b1a09 100644
85903--- a/kernel/trace/blktrace.c
85904+++ b/kernel/trace/blktrace.c
85905@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
85906 struct blk_trace *bt = filp->private_data;
85907 char buf[16];
85908
85909- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
85910+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
85911
85912 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
85913 }
85914@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
85915 return 1;
85916
85917 bt = buf->chan->private_data;
85918- atomic_inc(&bt->dropped);
85919+ atomic_inc_unchecked(&bt->dropped);
85920 return 0;
85921 }
85922
85923@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
85924
85925 bt->dir = dir;
85926 bt->dev = dev;
85927- atomic_set(&bt->dropped, 0);
85928+ atomic_set_unchecked(&bt->dropped, 0);
85929
85930 ret = -EIO;
85931 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
85932diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
85933index f23449d..b8cc3a1 100644
85934--- a/kernel/trace/ftrace.c
85935+++ b/kernel/trace/ftrace.c
85936@@ -1925,12 +1925,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
85937 if (unlikely(ftrace_disabled))
85938 return 0;
85939
85940+ ret = ftrace_arch_code_modify_prepare();
85941+ FTRACE_WARN_ON(ret);
85942+ if (ret)
85943+ return 0;
85944+
85945 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
85946+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
85947 if (ret) {
85948 ftrace_bug(ret, ip);
85949- return 0;
85950 }
85951- return 1;
85952+ return ret ? 0 : 1;
85953 }
85954
85955 /*
85956@@ -3994,8 +3999,10 @@ static int ftrace_process_locs(struct module *mod,
85957 if (!count)
85958 return 0;
85959
85960+ pax_open_kernel();
85961 sort(start, count, sizeof(*start),
85962 ftrace_cmp_ips, ftrace_swap_ips);
85963+ pax_close_kernel();
85964
85965 start_pg = ftrace_allocate_pages(count);
85966 if (!start_pg)
85967@@ -4718,8 +4725,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
85968 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
85969
85970 static int ftrace_graph_active;
85971-static struct notifier_block ftrace_suspend_notifier;
85972-
85973 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
85974 {
85975 return 0;
85976@@ -4863,6 +4868,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
85977 return NOTIFY_DONE;
85978 }
85979
85980+static struct notifier_block ftrace_suspend_notifier = {
85981+ .notifier_call = ftrace_suspend_notifier_call
85982+};
85983+
85984 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
85985 trace_func_graph_ent_t entryfunc)
85986 {
85987@@ -4876,7 +4885,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
85988 goto out;
85989 }
85990
85991- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
85992 register_pm_notifier(&ftrace_suspend_notifier);
85993
85994 ftrace_graph_active++;
85995diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
85996index e444ff8..438b8f4 100644
85997--- a/kernel/trace/ring_buffer.c
85998+++ b/kernel/trace/ring_buffer.c
85999@@ -352,9 +352,9 @@ struct buffer_data_page {
86000 */
86001 struct buffer_page {
86002 struct list_head list; /* list of buffer pages */
86003- local_t write; /* index for next write */
86004+ local_unchecked_t write; /* index for next write */
86005 unsigned read; /* index for next read */
86006- local_t entries; /* entries on this page */
86007+ local_unchecked_t entries; /* entries on this page */
86008 unsigned long real_end; /* real end of data */
86009 struct buffer_data_page *page; /* Actual data page */
86010 };
86011@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
86012 unsigned long last_overrun;
86013 local_t entries_bytes;
86014 local_t entries;
86015- local_t overrun;
86016- local_t commit_overrun;
86017+ local_unchecked_t overrun;
86018+ local_unchecked_t commit_overrun;
86019 local_t dropped_events;
86020 local_t committing;
86021 local_t commits;
86022@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86023 *
86024 * We add a counter to the write field to denote this.
86025 */
86026- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
86027- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
86028+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
86029+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
86030
86031 /*
86032 * Just make sure we have seen our old_write and synchronize
86033@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
86034 * cmpxchg to only update if an interrupt did not already
86035 * do it for us. If the cmpxchg fails, we don't care.
86036 */
86037- (void)local_cmpxchg(&next_page->write, old_write, val);
86038- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
86039+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
86040+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
86041
86042 /*
86043 * No need to worry about races with clearing out the commit.
86044@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
86045
86046 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
86047 {
86048- return local_read(&bpage->entries) & RB_WRITE_MASK;
86049+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
86050 }
86051
86052 static inline unsigned long rb_page_write(struct buffer_page *bpage)
86053 {
86054- return local_read(&bpage->write) & RB_WRITE_MASK;
86055+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
86056 }
86057
86058 static int
86059@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
86060 * bytes consumed in ring buffer from here.
86061 * Increment overrun to account for the lost events.
86062 */
86063- local_add(page_entries, &cpu_buffer->overrun);
86064+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
86065 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86066 }
86067
86068@@ -2063,7 +2063,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
86069 * it is our responsibility to update
86070 * the counters.
86071 */
86072- local_add(entries, &cpu_buffer->overrun);
86073+ local_add_unchecked(entries, &cpu_buffer->overrun);
86074 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
86075
86076 /*
86077@@ -2213,7 +2213,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86078 if (tail == BUF_PAGE_SIZE)
86079 tail_page->real_end = 0;
86080
86081- local_sub(length, &tail_page->write);
86082+ local_sub_unchecked(length, &tail_page->write);
86083 return;
86084 }
86085
86086@@ -2248,7 +2248,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86087 rb_event_set_padding(event);
86088
86089 /* Set the write back to the previous setting */
86090- local_sub(length, &tail_page->write);
86091+ local_sub_unchecked(length, &tail_page->write);
86092 return;
86093 }
86094
86095@@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
86096
86097 /* Set write to end of buffer */
86098 length = (tail + length) - BUF_PAGE_SIZE;
86099- local_sub(length, &tail_page->write);
86100+ local_sub_unchecked(length, &tail_page->write);
86101 }
86102
86103 /*
86104@@ -2286,7 +2286,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86105 * about it.
86106 */
86107 if (unlikely(next_page == commit_page)) {
86108- local_inc(&cpu_buffer->commit_overrun);
86109+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86110 goto out_reset;
86111 }
86112
86113@@ -2342,7 +2342,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
86114 cpu_buffer->tail_page) &&
86115 (cpu_buffer->commit_page ==
86116 cpu_buffer->reader_page))) {
86117- local_inc(&cpu_buffer->commit_overrun);
86118+ local_inc_unchecked(&cpu_buffer->commit_overrun);
86119 goto out_reset;
86120 }
86121 }
86122@@ -2390,7 +2390,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86123 length += RB_LEN_TIME_EXTEND;
86124
86125 tail_page = cpu_buffer->tail_page;
86126- write = local_add_return(length, &tail_page->write);
86127+ write = local_add_return_unchecked(length, &tail_page->write);
86128
86129 /* set write to only the index of the write */
86130 write &= RB_WRITE_MASK;
86131@@ -2407,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
86132 kmemcheck_annotate_bitfield(event, bitfield);
86133 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
86134
86135- local_inc(&tail_page->entries);
86136+ local_inc_unchecked(&tail_page->entries);
86137
86138 /*
86139 * If this is the first commit on the page, then update
86140@@ -2440,7 +2440,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
86141
86142 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
86143 unsigned long write_mask =
86144- local_read(&bpage->write) & ~RB_WRITE_MASK;
86145+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
86146 unsigned long event_length = rb_event_length(event);
86147 /*
86148 * This is on the tail page. It is possible that
86149@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
86150 */
86151 old_index += write_mask;
86152 new_index += write_mask;
86153- index = local_cmpxchg(&bpage->write, old_index, new_index);
86154+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
86155 if (index == old_index) {
86156 /* update counters */
86157 local_sub(event_length, &cpu_buffer->entries_bytes);
86158@@ -2842,7 +2842,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
86159
86160 /* Do the likely case first */
86161 if (likely(bpage->page == (void *)addr)) {
86162- local_dec(&bpage->entries);
86163+ local_dec_unchecked(&bpage->entries);
86164 return;
86165 }
86166
86167@@ -2854,7 +2854,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
86168 start = bpage;
86169 do {
86170 if (bpage->page == (void *)addr) {
86171- local_dec(&bpage->entries);
86172+ local_dec_unchecked(&bpage->entries);
86173 return;
86174 }
86175 rb_inc_page(cpu_buffer, &bpage);
86176@@ -3138,7 +3138,7 @@ static inline unsigned long
86177 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
86178 {
86179 return local_read(&cpu_buffer->entries) -
86180- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
86181+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
86182 }
86183
86184 /**
86185@@ -3227,7 +3227,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
86186 return 0;
86187
86188 cpu_buffer = buffer->buffers[cpu];
86189- ret = local_read(&cpu_buffer->overrun);
86190+ ret = local_read_unchecked(&cpu_buffer->overrun);
86191
86192 return ret;
86193 }
86194@@ -3250,7 +3250,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
86195 return 0;
86196
86197 cpu_buffer = buffer->buffers[cpu];
86198- ret = local_read(&cpu_buffer->commit_overrun);
86199+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
86200
86201 return ret;
86202 }
86203@@ -3335,7 +3335,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
86204 /* if you care about this being correct, lock the buffer */
86205 for_each_buffer_cpu(buffer, cpu) {
86206 cpu_buffer = buffer->buffers[cpu];
86207- overruns += local_read(&cpu_buffer->overrun);
86208+ overruns += local_read_unchecked(&cpu_buffer->overrun);
86209 }
86210
86211 return overruns;
86212@@ -3511,8 +3511,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86213 /*
86214 * Reset the reader page to size zero.
86215 */
86216- local_set(&cpu_buffer->reader_page->write, 0);
86217- local_set(&cpu_buffer->reader_page->entries, 0);
86218+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86219+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86220 local_set(&cpu_buffer->reader_page->page->commit, 0);
86221 cpu_buffer->reader_page->real_end = 0;
86222
86223@@ -3546,7 +3546,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
86224 * want to compare with the last_overrun.
86225 */
86226 smp_mb();
86227- overwrite = local_read(&(cpu_buffer->overrun));
86228+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
86229
86230 /*
86231 * Here's the tricky part.
86232@@ -4116,8 +4116,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86233
86234 cpu_buffer->head_page
86235 = list_entry(cpu_buffer->pages, struct buffer_page, list);
86236- local_set(&cpu_buffer->head_page->write, 0);
86237- local_set(&cpu_buffer->head_page->entries, 0);
86238+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
86239+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
86240 local_set(&cpu_buffer->head_page->page->commit, 0);
86241
86242 cpu_buffer->head_page->read = 0;
86243@@ -4127,14 +4127,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
86244
86245 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
86246 INIT_LIST_HEAD(&cpu_buffer->new_pages);
86247- local_set(&cpu_buffer->reader_page->write, 0);
86248- local_set(&cpu_buffer->reader_page->entries, 0);
86249+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
86250+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
86251 local_set(&cpu_buffer->reader_page->page->commit, 0);
86252 cpu_buffer->reader_page->read = 0;
86253
86254 local_set(&cpu_buffer->entries_bytes, 0);
86255- local_set(&cpu_buffer->overrun, 0);
86256- local_set(&cpu_buffer->commit_overrun, 0);
86257+ local_set_unchecked(&cpu_buffer->overrun, 0);
86258+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
86259 local_set(&cpu_buffer->dropped_events, 0);
86260 local_set(&cpu_buffer->entries, 0);
86261 local_set(&cpu_buffer->committing, 0);
86262@@ -4538,8 +4538,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
86263 rb_init_page(bpage);
86264 bpage = reader->page;
86265 reader->page = *data_page;
86266- local_set(&reader->write, 0);
86267- local_set(&reader->entries, 0);
86268+ local_set_unchecked(&reader->write, 0);
86269+ local_set_unchecked(&reader->entries, 0);
86270 reader->read = 0;
86271 *data_page = bpage;
86272
86273diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
86274index 0582a01..310bed1 100644
86275--- a/kernel/trace/trace.c
86276+++ b/kernel/trace/trace.c
86277@@ -3327,7 +3327,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
86278 return 0;
86279 }
86280
86281-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
86282+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
86283 {
86284 /* do nothing if flag is already set */
86285 if (!!(trace_flags & mask) == !!enabled)
86286diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
86287index 51b4448..7be601f 100644
86288--- a/kernel/trace/trace.h
86289+++ b/kernel/trace/trace.h
86290@@ -1035,7 +1035,7 @@ extern const char *__stop___trace_bprintk_fmt[];
86291 void trace_printk_init_buffers(void);
86292 void trace_printk_start_comm(void);
86293 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
86294-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
86295+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
86296
86297 /*
86298 * Normal trace_printk() and friends allocates special buffers
86299diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
86300index 26dc348..8708ca7 100644
86301--- a/kernel/trace/trace_clock.c
86302+++ b/kernel/trace/trace_clock.c
86303@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
86304 return now;
86305 }
86306
86307-static atomic64_t trace_counter;
86308+static atomic64_unchecked_t trace_counter;
86309
86310 /*
86311 * trace_clock_counter(): simply an atomic counter.
86312@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
86313 */
86314 u64 notrace trace_clock_counter(void)
86315 {
86316- return atomic64_add_return(1, &trace_counter);
86317+ return atomic64_inc_return_unchecked(&trace_counter);
86318 }
86319diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
86320index 3d18aad..d1be0eb 100644
86321--- a/kernel/trace/trace_events.c
86322+++ b/kernel/trace/trace_events.c
86323@@ -1794,10 +1794,6 @@ static LIST_HEAD(ftrace_module_file_list);
86324 struct ftrace_module_file_ops {
86325 struct list_head list;
86326 struct module *mod;
86327- struct file_operations id;
86328- struct file_operations enable;
86329- struct file_operations format;
86330- struct file_operations filter;
86331 };
86332
86333 static struct ftrace_module_file_ops *
86334@@ -1838,17 +1834,12 @@ trace_create_file_ops(struct module *mod)
86335
86336 file_ops->mod = mod;
86337
86338- file_ops->id = ftrace_event_id_fops;
86339- file_ops->id.owner = mod;
86340-
86341- file_ops->enable = ftrace_enable_fops;
86342- file_ops->enable.owner = mod;
86343-
86344- file_ops->filter = ftrace_event_filter_fops;
86345- file_ops->filter.owner = mod;
86346-
86347- file_ops->format = ftrace_event_format_fops;
86348- file_ops->format.owner = mod;
86349+ pax_open_kernel();
86350+ mod->trace_id.owner = mod;
86351+ mod->trace_enable.owner = mod;
86352+ mod->trace_filter.owner = mod;
86353+ mod->trace_format.owner = mod;
86354+ pax_close_kernel();
86355
86356 list_add(&file_ops->list, &ftrace_module_file_list);
86357
86358@@ -1941,8 +1932,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
86359 struct ftrace_module_file_ops *file_ops)
86360 {
86361 return __trace_add_new_event(call, tr,
86362- &file_ops->id, &file_ops->enable,
86363- &file_ops->filter, &file_ops->format);
86364+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
86365+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
86366 }
86367
86368 #else
86369diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
86370index a5e8f48..a9690d2 100644
86371--- a/kernel/trace/trace_mmiotrace.c
86372+++ b/kernel/trace/trace_mmiotrace.c
86373@@ -24,7 +24,7 @@ struct header_iter {
86374 static struct trace_array *mmio_trace_array;
86375 static bool overrun_detected;
86376 static unsigned long prev_overruns;
86377-static atomic_t dropped_count;
86378+static atomic_unchecked_t dropped_count;
86379
86380 static void mmio_reset_data(struct trace_array *tr)
86381 {
86382@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
86383
86384 static unsigned long count_overruns(struct trace_iterator *iter)
86385 {
86386- unsigned long cnt = atomic_xchg(&dropped_count, 0);
86387+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
86388 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
86389
86390 if (over > prev_overruns)
86391@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
86392 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
86393 sizeof(*entry), 0, pc);
86394 if (!event) {
86395- atomic_inc(&dropped_count);
86396+ atomic_inc_unchecked(&dropped_count);
86397 return;
86398 }
86399 entry = ring_buffer_event_data(event);
86400@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
86401 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
86402 sizeof(*entry), 0, pc);
86403 if (!event) {
86404- atomic_inc(&dropped_count);
86405+ atomic_inc_unchecked(&dropped_count);
86406 return;
86407 }
86408 entry = ring_buffer_event_data(event);
86409diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
86410index bb922d9..2a54a257 100644
86411--- a/kernel/trace/trace_output.c
86412+++ b/kernel/trace/trace_output.c
86413@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
86414
86415 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
86416 if (!IS_ERR(p)) {
86417- p = mangle_path(s->buffer + s->len, p, "\n");
86418+ p = mangle_path(s->buffer + s->len, p, "\n\\");
86419 if (p) {
86420 s->len = p - s->buffer;
86421 return 1;
86422@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
86423 goto out;
86424 }
86425
86426+ pax_open_kernel();
86427 if (event->funcs->trace == NULL)
86428- event->funcs->trace = trace_nop_print;
86429+ *(void **)&event->funcs->trace = trace_nop_print;
86430 if (event->funcs->raw == NULL)
86431- event->funcs->raw = trace_nop_print;
86432+ *(void **)&event->funcs->raw = trace_nop_print;
86433 if (event->funcs->hex == NULL)
86434- event->funcs->hex = trace_nop_print;
86435+ *(void **)&event->funcs->hex = trace_nop_print;
86436 if (event->funcs->binary == NULL)
86437- event->funcs->binary = trace_nop_print;
86438+ *(void **)&event->funcs->binary = trace_nop_print;
86439+ pax_close_kernel();
86440
86441 key = event->type & (EVENT_HASHSIZE - 1);
86442
86443diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
86444index b20428c..4845a10 100644
86445--- a/kernel/trace/trace_stack.c
86446+++ b/kernel/trace/trace_stack.c
86447@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
86448 return;
86449
86450 /* we do not handle interrupt stacks yet */
86451- if (!object_is_on_stack(stack))
86452+ if (!object_starts_on_stack(stack))
86453 return;
86454
86455 local_irq_save(flags);
86456diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
86457index 9064b91..1f5d2f8 100644
86458--- a/kernel/user_namespace.c
86459+++ b/kernel/user_namespace.c
86460@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
86461 !kgid_has_mapping(parent_ns, group))
86462 return -EPERM;
86463
86464+#ifdef CONFIG_GRKERNSEC
86465+ /*
86466+ * This doesn't really inspire confidence:
86467+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
86468+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
86469+ * Increases kernel attack surface in areas developers
86470+ * previously cared little about ("low importance due
86471+ * to requiring "root" capability")
86472+ * To be removed when this code receives *proper* review
86473+ */
86474+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
86475+ !capable(CAP_SETGID))
86476+ return -EPERM;
86477+#endif
86478+
86479 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
86480 if (!ns)
86481 return -ENOMEM;
86482@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
86483 if (atomic_read(&current->mm->mm_users) > 1)
86484 return -EINVAL;
86485
86486- if (current->fs->users != 1)
86487+ if (atomic_read(&current->fs->users) != 1)
86488 return -EINVAL;
86489
86490 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
86491diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
86492index 4f69f9a..7c6f8f8 100644
86493--- a/kernel/utsname_sysctl.c
86494+++ b/kernel/utsname_sysctl.c
86495@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
86496 static int proc_do_uts_string(ctl_table *table, int write,
86497 void __user *buffer, size_t *lenp, loff_t *ppos)
86498 {
86499- struct ctl_table uts_table;
86500+ ctl_table_no_const uts_table;
86501 int r;
86502 memcpy(&uts_table, table, sizeof(uts_table));
86503 uts_table.data = get_uts(table, write);
86504diff --git a/kernel/watchdog.c b/kernel/watchdog.c
86505index 05039e3..17490c7 100644
86506--- a/kernel/watchdog.c
86507+++ b/kernel/watchdog.c
86508@@ -531,7 +531,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
86509 }
86510 #endif /* CONFIG_SYSCTL */
86511
86512-static struct smp_hotplug_thread watchdog_threads = {
86513+static struct smp_hotplug_thread watchdog_threads __read_only = {
86514 .store = &softlockup_watchdog,
86515 .thread_should_run = watchdog_should_run,
86516 .thread_fn = watchdog,
86517diff --git a/kernel/workqueue.c b/kernel/workqueue.c
86518index 6f01921..139869b 100644
86519--- a/kernel/workqueue.c
86520+++ b/kernel/workqueue.c
86521@@ -4596,7 +4596,7 @@ static void rebind_workers(struct worker_pool *pool)
86522 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
86523 worker_flags |= WORKER_REBOUND;
86524 worker_flags &= ~WORKER_UNBOUND;
86525- ACCESS_ONCE(worker->flags) = worker_flags;
86526+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
86527 }
86528
86529 spin_unlock_irq(&pool->lock);
86530diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
86531index 74fdc5c..3310593 100644
86532--- a/lib/Kconfig.debug
86533+++ b/lib/Kconfig.debug
86534@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
86535
86536 config DEBUG_LOCK_ALLOC
86537 bool "Lock debugging: detect incorrect freeing of live locks"
86538- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86539+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86540 select DEBUG_SPINLOCK
86541 select DEBUG_MUTEXES
86542 select LOCKDEP
86543@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
86544
86545 config PROVE_LOCKING
86546 bool "Lock debugging: prove locking correctness"
86547- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86548+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86549 select LOCKDEP
86550 select DEBUG_SPINLOCK
86551 select DEBUG_MUTEXES
86552@@ -614,7 +614,7 @@ config LOCKDEP
86553
86554 config LOCK_STAT
86555 bool "Lock usage statistics"
86556- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86557+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86558 select LOCKDEP
86559 select DEBUG_SPINLOCK
86560 select DEBUG_MUTEXES
86561@@ -1282,6 +1282,7 @@ config LATENCYTOP
86562 depends on DEBUG_KERNEL
86563 depends on STACKTRACE_SUPPORT
86564 depends on PROC_FS
86565+ depends on !GRKERNSEC_HIDESYM
86566 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
86567 select KALLSYMS
86568 select KALLSYMS_ALL
86569@@ -1298,7 +1299,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86570 config DEBUG_STRICT_USER_COPY_CHECKS
86571 bool "Strict user copy size checks"
86572 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86573- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
86574+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
86575 help
86576 Enabling this option turns a certain set of sanity checks for user
86577 copy operations into compile time failures.
86578@@ -1328,7 +1329,7 @@ config INTERVAL_TREE_TEST
86579
86580 config PROVIDE_OHCI1394_DMA_INIT
86581 bool "Remote debugging over FireWire early on boot"
86582- depends on PCI && X86
86583+ depends on PCI && X86 && !GRKERNSEC
86584 help
86585 If you want to debug problems which hang or crash the kernel early
86586 on boot and the crashing machine has a FireWire port, you can use
86587@@ -1357,7 +1358,7 @@ config PROVIDE_OHCI1394_DMA_INIT
86588
86589 config FIREWIRE_OHCI_REMOTE_DMA
86590 bool "Remote debugging over FireWire with firewire-ohci"
86591- depends on FIREWIRE_OHCI
86592+ depends on FIREWIRE_OHCI && !GRKERNSEC
86593 help
86594 This option lets you use the FireWire bus for remote debugging
86595 with help of the firewire-ohci driver. It enables unfiltered
86596diff --git a/lib/Makefile b/lib/Makefile
86597index c55a037..fb46e3b 100644
86598--- a/lib/Makefile
86599+++ b/lib/Makefile
86600@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
86601
86602 obj-$(CONFIG_BTREE) += btree.o
86603 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
86604-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
86605+obj-y += list_debug.o
86606 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
86607
86608 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
86609diff --git a/lib/bitmap.c b/lib/bitmap.c
86610index 06f7e4f..f3cf2b0 100644
86611--- a/lib/bitmap.c
86612+++ b/lib/bitmap.c
86613@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
86614 {
86615 int c, old_c, totaldigits, ndigits, nchunks, nbits;
86616 u32 chunk;
86617- const char __user __force *ubuf = (const char __user __force *)buf;
86618+ const char __user *ubuf = (const char __force_user *)buf;
86619
86620 bitmap_zero(maskp, nmaskbits);
86621
86622@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
86623 {
86624 if (!access_ok(VERIFY_READ, ubuf, ulen))
86625 return -EFAULT;
86626- return __bitmap_parse((const char __force *)ubuf,
86627+ return __bitmap_parse((const char __force_kernel *)ubuf,
86628 ulen, 1, maskp, nmaskbits);
86629
86630 }
86631@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
86632 {
86633 unsigned a, b;
86634 int c, old_c, totaldigits;
86635- const char __user __force *ubuf = (const char __user __force *)buf;
86636+ const char __user *ubuf = (const char __force_user *)buf;
86637 int exp_digit, in_range;
86638
86639 totaldigits = c = 0;
86640@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
86641 {
86642 if (!access_ok(VERIFY_READ, ubuf, ulen))
86643 return -EFAULT;
86644- return __bitmap_parselist((const char __force *)ubuf,
86645+ return __bitmap_parselist((const char __force_kernel *)ubuf,
86646 ulen, 1, maskp, nmaskbits);
86647 }
86648 EXPORT_SYMBOL(bitmap_parselist_user);
86649diff --git a/lib/bug.c b/lib/bug.c
86650index 1686034..a9c00c8 100644
86651--- a/lib/bug.c
86652+++ b/lib/bug.c
86653@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
86654 return BUG_TRAP_TYPE_NONE;
86655
86656 bug = find_bug(bugaddr);
86657+ if (!bug)
86658+ return BUG_TRAP_TYPE_NONE;
86659
86660 file = NULL;
86661 line = 0;
86662diff --git a/lib/debugobjects.c b/lib/debugobjects.c
86663index 37061ed..da83f48 100644
86664--- a/lib/debugobjects.c
86665+++ b/lib/debugobjects.c
86666@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
86667 if (limit > 4)
86668 return;
86669
86670- is_on_stack = object_is_on_stack(addr);
86671+ is_on_stack = object_starts_on_stack(addr);
86672 if (is_on_stack == onstack)
86673 return;
86674
86675diff --git a/lib/devres.c b/lib/devres.c
86676index 8235331..5881053 100644
86677--- a/lib/devres.c
86678+++ b/lib/devres.c
86679@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
86680 void devm_iounmap(struct device *dev, void __iomem *addr)
86681 {
86682 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
86683- (void *)addr));
86684+ (void __force *)addr));
86685 iounmap(addr);
86686 }
86687 EXPORT_SYMBOL(devm_iounmap);
86688@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
86689 {
86690 ioport_unmap(addr);
86691 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
86692- devm_ioport_map_match, (void *)addr));
86693+ devm_ioport_map_match, (void __force *)addr));
86694 }
86695 EXPORT_SYMBOL(devm_ioport_unmap);
86696 #endif /* CONFIG_HAS_IOPORT */
86697diff --git a/lib/div64.c b/lib/div64.c
86698index a163b6c..9618fa5 100644
86699--- a/lib/div64.c
86700+++ b/lib/div64.c
86701@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
86702 EXPORT_SYMBOL(__div64_32);
86703
86704 #ifndef div_s64_rem
86705-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86706+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86707 {
86708 u64 quotient;
86709
86710@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
86711 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
86712 */
86713 #ifndef div64_u64
86714-u64 div64_u64(u64 dividend, u64 divisor)
86715+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
86716 {
86717 u32 high = divisor >> 32;
86718 u64 quot;
86719diff --git a/lib/dma-debug.c b/lib/dma-debug.c
86720index d87a17a..ac0d79a 100644
86721--- a/lib/dma-debug.c
86722+++ b/lib/dma-debug.c
86723@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
86724
86725 void dma_debug_add_bus(struct bus_type *bus)
86726 {
86727- struct notifier_block *nb;
86728+ notifier_block_no_const *nb;
86729
86730 if (global_disable)
86731 return;
86732@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
86733
86734 static void check_for_stack(struct device *dev, void *addr)
86735 {
86736- if (object_is_on_stack(addr))
86737+ if (object_starts_on_stack(addr))
86738 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
86739 "stack [addr=%p]\n", addr);
86740 }
86741diff --git a/lib/inflate.c b/lib/inflate.c
86742index 013a761..c28f3fc 100644
86743--- a/lib/inflate.c
86744+++ b/lib/inflate.c
86745@@ -269,7 +269,7 @@ static void free(void *where)
86746 malloc_ptr = free_mem_ptr;
86747 }
86748 #else
86749-#define malloc(a) kmalloc(a, GFP_KERNEL)
86750+#define malloc(a) kmalloc((a), GFP_KERNEL)
86751 #define free(a) kfree(a)
86752 #endif
86753
86754diff --git a/lib/ioremap.c b/lib/ioremap.c
86755index 0c9216c..863bd89 100644
86756--- a/lib/ioremap.c
86757+++ b/lib/ioremap.c
86758@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
86759 unsigned long next;
86760
86761 phys_addr -= addr;
86762- pmd = pmd_alloc(&init_mm, pud, addr);
86763+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
86764 if (!pmd)
86765 return -ENOMEM;
86766 do {
86767@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
86768 unsigned long next;
86769
86770 phys_addr -= addr;
86771- pud = pud_alloc(&init_mm, pgd, addr);
86772+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
86773 if (!pud)
86774 return -ENOMEM;
86775 do {
86776diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
86777index bd2bea9..6b3c95e 100644
86778--- a/lib/is_single_threaded.c
86779+++ b/lib/is_single_threaded.c
86780@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
86781 struct task_struct *p, *t;
86782 bool ret;
86783
86784+ if (!mm)
86785+ return true;
86786+
86787 if (atomic_read(&task->signal->live) != 1)
86788 return false;
86789
86790diff --git a/lib/kobject.c b/lib/kobject.c
86791index b7e29a6..2f3ca75 100644
86792--- a/lib/kobject.c
86793+++ b/lib/kobject.c
86794@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
86795 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
86796 if (!kset)
86797 return NULL;
86798- retval = kobject_set_name(&kset->kobj, name);
86799+ retval = kobject_set_name(&kset->kobj, "%s", name);
86800 if (retval) {
86801 kfree(kset);
86802 return NULL;
86803@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
86804
86805
86806 static DEFINE_SPINLOCK(kobj_ns_type_lock);
86807-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
86808+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
86809
86810-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86811+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86812 {
86813 enum kobj_ns_type type = ops->type;
86814 int error;
86815diff --git a/lib/list_debug.c b/lib/list_debug.c
86816index c24c2f7..06e070b 100644
86817--- a/lib/list_debug.c
86818+++ b/lib/list_debug.c
86819@@ -11,7 +11,9 @@
86820 #include <linux/bug.h>
86821 #include <linux/kernel.h>
86822 #include <linux/rculist.h>
86823+#include <linux/mm.h>
86824
86825+#ifdef CONFIG_DEBUG_LIST
86826 /*
86827 * Insert a new entry between two known consecutive entries.
86828 *
86829@@ -19,21 +21,32 @@
86830 * the prev/next entries already!
86831 */
86832
86833-void __list_add(struct list_head *new,
86834- struct list_head *prev,
86835- struct list_head *next)
86836+static bool __list_add_debug(struct list_head *new,
86837+ struct list_head *prev,
86838+ struct list_head *next)
86839 {
86840- WARN(next->prev != prev,
86841+ if (WARN(next->prev != prev,
86842 "list_add corruption. next->prev should be "
86843 "prev (%p), but was %p. (next=%p).\n",
86844- prev, next->prev, next);
86845- WARN(prev->next != next,
86846+ prev, next->prev, next) ||
86847+ WARN(prev->next != next,
86848 "list_add corruption. prev->next should be "
86849 "next (%p), but was %p. (prev=%p).\n",
86850- next, prev->next, prev);
86851- WARN(new == prev || new == next,
86852- "list_add double add: new=%p, prev=%p, next=%p.\n",
86853- new, prev, next);
86854+ next, prev->next, prev) ||
86855+ WARN(new == prev || new == next,
86856+ "list_add double add: new=%p, prev=%p, next=%p.\n",
86857+ new, prev, next))
86858+ return false;
86859+ return true;
86860+}
86861+
86862+void __list_add(struct list_head *new,
86863+ struct list_head *prev,
86864+ struct list_head *next)
86865+{
86866+ if (!__list_add_debug(new, prev, next))
86867+ return;
86868+
86869 next->prev = new;
86870 new->next = next;
86871 new->prev = prev;
86872@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
86873 }
86874 EXPORT_SYMBOL(__list_add);
86875
86876-void __list_del_entry(struct list_head *entry)
86877+static bool __list_del_entry_debug(struct list_head *entry)
86878 {
86879 struct list_head *prev, *next;
86880
86881@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
86882 WARN(next->prev != entry,
86883 "list_del corruption. next->prev should be %p, "
86884 "but was %p\n", entry, next->prev))
86885+ return false;
86886+ return true;
86887+}
86888+
86889+void __list_del_entry(struct list_head *entry)
86890+{
86891+ if (!__list_del_entry_debug(entry))
86892 return;
86893
86894- __list_del(prev, next);
86895+ __list_del(entry->prev, entry->next);
86896 }
86897 EXPORT_SYMBOL(__list_del_entry);
86898
86899@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
86900 void __list_add_rcu(struct list_head *new,
86901 struct list_head *prev, struct list_head *next)
86902 {
86903- WARN(next->prev != prev,
86904- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
86905- prev, next->prev, next);
86906- WARN(prev->next != next,
86907- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
86908- next, prev->next, prev);
86909+ if (!__list_add_debug(new, prev, next))
86910+ return;
86911+
86912 new->next = next;
86913 new->prev = prev;
86914 rcu_assign_pointer(list_next_rcu(prev), new);
86915 next->prev = new;
86916 }
86917 EXPORT_SYMBOL(__list_add_rcu);
86918+#endif
86919+
86920+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
86921+{
86922+#ifdef CONFIG_DEBUG_LIST
86923+ if (!__list_add_debug(new, prev, next))
86924+ return;
86925+#endif
86926+
86927+ pax_open_kernel();
86928+ next->prev = new;
86929+ new->next = next;
86930+ new->prev = prev;
86931+ prev->next = new;
86932+ pax_close_kernel();
86933+}
86934+EXPORT_SYMBOL(__pax_list_add);
86935+
86936+void pax_list_del(struct list_head *entry)
86937+{
86938+#ifdef CONFIG_DEBUG_LIST
86939+ if (!__list_del_entry_debug(entry))
86940+ return;
86941+#endif
86942+
86943+ pax_open_kernel();
86944+ __list_del(entry->prev, entry->next);
86945+ entry->next = LIST_POISON1;
86946+ entry->prev = LIST_POISON2;
86947+ pax_close_kernel();
86948+}
86949+EXPORT_SYMBOL(pax_list_del);
86950+
86951+void pax_list_del_init(struct list_head *entry)
86952+{
86953+ pax_open_kernel();
86954+ __list_del(entry->prev, entry->next);
86955+ INIT_LIST_HEAD(entry);
86956+ pax_close_kernel();
86957+}
86958+EXPORT_SYMBOL(pax_list_del_init);
86959+
86960+void __pax_list_add_rcu(struct list_head *new,
86961+ struct list_head *prev, struct list_head *next)
86962+{
86963+#ifdef CONFIG_DEBUG_LIST
86964+ if (!__list_add_debug(new, prev, next))
86965+ return;
86966+#endif
86967+
86968+ pax_open_kernel();
86969+ new->next = next;
86970+ new->prev = prev;
86971+ rcu_assign_pointer(list_next_rcu(prev), new);
86972+ next->prev = new;
86973+ pax_close_kernel();
86974+}
86975+EXPORT_SYMBOL(__pax_list_add_rcu);
86976+
86977+void pax_list_del_rcu(struct list_head *entry)
86978+{
86979+#ifdef CONFIG_DEBUG_LIST
86980+ if (!__list_del_entry_debug(entry))
86981+ return;
86982+#endif
86983+
86984+ pax_open_kernel();
86985+ __list_del(entry->prev, entry->next);
86986+ entry->next = LIST_POISON1;
86987+ entry->prev = LIST_POISON2;
86988+ pax_close_kernel();
86989+}
86990+EXPORT_SYMBOL(pax_list_del_rcu);
86991diff --git a/lib/radix-tree.c b/lib/radix-tree.c
86992index e796429..6e38f9f 100644
86993--- a/lib/radix-tree.c
86994+++ b/lib/radix-tree.c
86995@@ -92,7 +92,7 @@ struct radix_tree_preload {
86996 int nr;
86997 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
86998 };
86999-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
87000+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
87001
87002 static inline void *ptr_to_indirect(void *ptr)
87003 {
87004diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
87005index bb2b201..46abaf9 100644
87006--- a/lib/strncpy_from_user.c
87007+++ b/lib/strncpy_from_user.c
87008@@ -21,7 +21,7 @@
87009 */
87010 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
87011 {
87012- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87013+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87014 long res = 0;
87015
87016 /*
87017diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
87018index a28df52..3d55877 100644
87019--- a/lib/strnlen_user.c
87020+++ b/lib/strnlen_user.c
87021@@ -26,7 +26,7 @@
87022 */
87023 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
87024 {
87025- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87026+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
87027 long align, res = 0;
87028 unsigned long c;
87029
87030diff --git a/lib/swiotlb.c b/lib/swiotlb.c
87031index d23762e..e21eab2 100644
87032--- a/lib/swiotlb.c
87033+++ b/lib/swiotlb.c
87034@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
87035
87036 void
87037 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
87038- dma_addr_t dev_addr)
87039+ dma_addr_t dev_addr, struct dma_attrs *attrs)
87040 {
87041 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
87042
87043diff --git a/lib/usercopy.c b/lib/usercopy.c
87044index 4f5b1dd..7cab418 100644
87045--- a/lib/usercopy.c
87046+++ b/lib/usercopy.c
87047@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
87048 WARN(1, "Buffer overflow detected!\n");
87049 }
87050 EXPORT_SYMBOL(copy_from_user_overflow);
87051+
87052+void copy_to_user_overflow(void)
87053+{
87054+ WARN(1, "Buffer overflow detected!\n");
87055+}
87056+EXPORT_SYMBOL(copy_to_user_overflow);
87057diff --git a/lib/vsprintf.c b/lib/vsprintf.c
87058index e149c64..24aa71a 100644
87059--- a/lib/vsprintf.c
87060+++ b/lib/vsprintf.c
87061@@ -16,6 +16,9 @@
87062 * - scnprintf and vscnprintf
87063 */
87064
87065+#ifdef CONFIG_GRKERNSEC_HIDESYM
87066+#define __INCLUDED_BY_HIDESYM 1
87067+#endif
87068 #include <stdarg.h>
87069 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
87070 #include <linux/types.h>
87071@@ -981,7 +984,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
87072 return number(buf, end, *(const netdev_features_t *)addr, spec);
87073 }
87074
87075+#ifdef CONFIG_GRKERNSEC_HIDESYM
87076+int kptr_restrict __read_mostly = 2;
87077+#else
87078 int kptr_restrict __read_mostly;
87079+#endif
87080
87081 /*
87082 * Show a '%p' thing. A kernel extension is that the '%p' is followed
87083@@ -994,6 +1001,7 @@ int kptr_restrict __read_mostly;
87084 * - 'f' For simple symbolic function names without offset
87085 * - 'S' For symbolic direct pointers with offset
87086 * - 's' For symbolic direct pointers without offset
87087+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
87088 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
87089 * - 'B' For backtraced symbolic direct pointers with offset
87090 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
87091@@ -1052,12 +1060,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87092
87093 if (!ptr && *fmt != 'K') {
87094 /*
87095- * Print (null) with the same width as a pointer so it makes
87096+ * Print (nil) with the same width as a pointer so it makes
87097 * tabular output look nice.
87098 */
87099 if (spec.field_width == -1)
87100 spec.field_width = default_width;
87101- return string(buf, end, "(null)", spec);
87102+ return string(buf, end, "(nil)", spec);
87103 }
87104
87105 switch (*fmt) {
87106@@ -1067,6 +1075,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87107 /* Fallthrough */
87108 case 'S':
87109 case 's':
87110+#ifdef CONFIG_GRKERNSEC_HIDESYM
87111+ break;
87112+#else
87113+ return symbol_string(buf, end, ptr, spec, fmt);
87114+#endif
87115+ case 'A':
87116 case 'B':
87117 return symbol_string(buf, end, ptr, spec, fmt);
87118 case 'R':
87119@@ -1107,6 +1121,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87120 va_end(va);
87121 return buf;
87122 }
87123+ case 'P':
87124+ break;
87125 case 'K':
87126 /*
87127 * %pK cannot be used in IRQ context because its test
87128@@ -1136,6 +1152,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
87129 return number(buf, end,
87130 (unsigned long long) *((phys_addr_t *)ptr), spec);
87131 }
87132+
87133+#ifdef CONFIG_GRKERNSEC_HIDESYM
87134+ /* 'P' = approved pointers to copy to userland,
87135+ as in the /proc/kallsyms case, as we make it display nothing
87136+ for non-root users, and the real contents for root users
87137+ Also ignore 'K' pointers, since we force their NULLing for non-root users
87138+ above
87139+ */
87140+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
87141+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
87142+ dump_stack();
87143+ ptr = NULL;
87144+ }
87145+#endif
87146+
87147 spec.flags |= SMALL;
87148 if (spec.field_width == -1) {
87149 spec.field_width = default_width;
87150@@ -1857,11 +1888,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
87151 typeof(type) value; \
87152 if (sizeof(type) == 8) { \
87153 args = PTR_ALIGN(args, sizeof(u32)); \
87154- *(u32 *)&value = *(u32 *)args; \
87155- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
87156+ *(u32 *)&value = *(const u32 *)args; \
87157+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
87158 } else { \
87159 args = PTR_ALIGN(args, sizeof(type)); \
87160- value = *(typeof(type) *)args; \
87161+ value = *(const typeof(type) *)args; \
87162 } \
87163 args += sizeof(type); \
87164 value; \
87165@@ -1924,7 +1955,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
87166 case FORMAT_TYPE_STR: {
87167 const char *str_arg = args;
87168 args += strlen(str_arg) + 1;
87169- str = string(str, end, (char *)str_arg, spec);
87170+ str = string(str, end, str_arg, spec);
87171 break;
87172 }
87173
87174diff --git a/localversion-grsec b/localversion-grsec
87175new file mode 100644
87176index 0000000..7cd6065
87177--- /dev/null
87178+++ b/localversion-grsec
87179@@ -0,0 +1 @@
87180+-grsec
87181diff --git a/mm/Kconfig b/mm/Kconfig
87182index e742d06..c56fdd8 100644
87183--- a/mm/Kconfig
87184+++ b/mm/Kconfig
87185@@ -317,10 +317,10 @@ config KSM
87186 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
87187
87188 config DEFAULT_MMAP_MIN_ADDR
87189- int "Low address space to protect from user allocation"
87190+ int "Low address space to protect from user allocation"
87191 depends on MMU
87192- default 4096
87193- help
87194+ default 65536
87195+ help
87196 This is the portion of low virtual memory which should be protected
87197 from userspace allocation. Keeping a user from writing to low pages
87198 can help reduce the impact of kernel NULL pointer bugs.
87199@@ -351,7 +351,7 @@ config MEMORY_FAILURE
87200
87201 config HWPOISON_INJECT
87202 tristate "HWPoison pages injector"
87203- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
87204+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
87205 select PROC_PAGE_MONITOR
87206
87207 config NOMMU_INITIAL_TRIM_EXCESS
87208diff --git a/mm/backing-dev.c b/mm/backing-dev.c
87209index 5025174..9d67dcd 100644
87210--- a/mm/backing-dev.c
87211+++ b/mm/backing-dev.c
87212@@ -12,7 +12,7 @@
87213 #include <linux/device.h>
87214 #include <trace/events/writeback.h>
87215
87216-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
87217+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
87218
87219 struct backing_dev_info default_backing_dev_info = {
87220 .name = "default",
87221@@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
87222 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
87223 unsigned int cap)
87224 {
87225- char tmp[32];
87226 int err;
87227
87228 bdi->name = name;
87229@@ -524,8 +523,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
87230 if (err)
87231 return err;
87232
87233- sprintf(tmp, "%.28s%s", name, "-%d");
87234- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
87235+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return_unchecked(&bdi_seq));
87236 if (err) {
87237 bdi_destroy(bdi);
87238 return err;
87239diff --git a/mm/filemap.c b/mm/filemap.c
87240index 7905fe7..f59502b 100644
87241--- a/mm/filemap.c
87242+++ b/mm/filemap.c
87243@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
87244 struct address_space *mapping = file->f_mapping;
87245
87246 if (!mapping->a_ops->readpage)
87247- return -ENOEXEC;
87248+ return -ENODEV;
87249 file_accessed(file);
87250 vma->vm_ops = &generic_file_vm_ops;
87251 return 0;
87252@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
87253
87254 while (bytes) {
87255 char __user *buf = iov->iov_base + base;
87256- int copy = min(bytes, iov->iov_len - base);
87257+ size_t copy = min(bytes, iov->iov_len - base);
87258
87259 base = 0;
87260 left = __copy_from_user_inatomic(vaddr, buf, copy);
87261@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
87262 BUG_ON(!in_atomic());
87263 kaddr = kmap_atomic(page);
87264 if (likely(i->nr_segs == 1)) {
87265- int left;
87266+ size_t left;
87267 char __user *buf = i->iov->iov_base + i->iov_offset;
87268 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
87269 copied = bytes - left;
87270@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
87271
87272 kaddr = kmap(page);
87273 if (likely(i->nr_segs == 1)) {
87274- int left;
87275+ size_t left;
87276 char __user *buf = i->iov->iov_base + i->iov_offset;
87277 left = __copy_from_user(kaddr + offset, buf, bytes);
87278 copied = bytes - left;
87279@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
87280 * zero-length segments (without overruning the iovec).
87281 */
87282 while (bytes || unlikely(i->count && !iov->iov_len)) {
87283- int copy;
87284+ size_t copy;
87285
87286 copy = min(bytes, iov->iov_len - base);
87287 BUG_ON(!i->count || i->count < copy);
87288@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
87289 *pos = i_size_read(inode);
87290
87291 if (limit != RLIM_INFINITY) {
87292+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
87293 if (*pos >= limit) {
87294 send_sig(SIGXFSZ, current, 0);
87295 return -EFBIG;
87296diff --git a/mm/fremap.c b/mm/fremap.c
87297index 87da359..3f41cb1 100644
87298--- a/mm/fremap.c
87299+++ b/mm/fremap.c
87300@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
87301 retry:
87302 vma = find_vma(mm, start);
87303
87304+#ifdef CONFIG_PAX_SEGMEXEC
87305+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
87306+ goto out;
87307+#endif
87308+
87309 /*
87310 * Make sure the vma is shared, that it supports prefaulting,
87311 * and that the remapped range is valid and fully within
87312diff --git a/mm/highmem.c b/mm/highmem.c
87313index b32b70c..e512eb0 100644
87314--- a/mm/highmem.c
87315+++ b/mm/highmem.c
87316@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
87317 * So no dangers, even with speculative execution.
87318 */
87319 page = pte_page(pkmap_page_table[i]);
87320+ pax_open_kernel();
87321 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
87322-
87323+ pax_close_kernel();
87324 set_page_address(page, NULL);
87325 need_flush = 1;
87326 }
87327@@ -198,9 +199,11 @@ start:
87328 }
87329 }
87330 vaddr = PKMAP_ADDR(last_pkmap_nr);
87331+
87332+ pax_open_kernel();
87333 set_pte_at(&init_mm, vaddr,
87334 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
87335-
87336+ pax_close_kernel();
87337 pkmap_count[last_pkmap_nr] = 1;
87338 set_page_address(page, (void *)vaddr);
87339
87340diff --git a/mm/hugetlb.c b/mm/hugetlb.c
87341index 7c5eb85..5c01c2f 100644
87342--- a/mm/hugetlb.c
87343+++ b/mm/hugetlb.c
87344@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
87345 struct hstate *h = &default_hstate;
87346 unsigned long tmp;
87347 int ret;
87348+ ctl_table_no_const hugetlb_table;
87349
87350 tmp = h->max_huge_pages;
87351
87352 if (write && h->order >= MAX_ORDER)
87353 return -EINVAL;
87354
87355- table->data = &tmp;
87356- table->maxlen = sizeof(unsigned long);
87357- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87358+ hugetlb_table = *table;
87359+ hugetlb_table.data = &tmp;
87360+ hugetlb_table.maxlen = sizeof(unsigned long);
87361+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87362 if (ret)
87363 goto out;
87364
87365@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
87366 struct hstate *h = &default_hstate;
87367 unsigned long tmp;
87368 int ret;
87369+ ctl_table_no_const hugetlb_table;
87370
87371 tmp = h->nr_overcommit_huge_pages;
87372
87373 if (write && h->order >= MAX_ORDER)
87374 return -EINVAL;
87375
87376- table->data = &tmp;
87377- table->maxlen = sizeof(unsigned long);
87378- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87379+ hugetlb_table = *table;
87380+ hugetlb_table.data = &tmp;
87381+ hugetlb_table.maxlen = sizeof(unsigned long);
87382+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87383 if (ret)
87384 goto out;
87385
87386@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
87387 return 1;
87388 }
87389
87390+#ifdef CONFIG_PAX_SEGMEXEC
87391+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
87392+{
87393+ struct mm_struct *mm = vma->vm_mm;
87394+ struct vm_area_struct *vma_m;
87395+ unsigned long address_m;
87396+ pte_t *ptep_m;
87397+
87398+ vma_m = pax_find_mirror_vma(vma);
87399+ if (!vma_m)
87400+ return;
87401+
87402+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87403+ address_m = address + SEGMEXEC_TASK_SIZE;
87404+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
87405+ get_page(page_m);
87406+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
87407+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
87408+}
87409+#endif
87410+
87411 /*
87412 * Hugetlb_cow() should be called with page lock of the original hugepage held.
87413 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
87414@@ -2663,6 +2688,11 @@ retry_avoidcopy:
87415 make_huge_pte(vma, new_page, 1));
87416 page_remove_rmap(old_page);
87417 hugepage_add_new_anon_rmap(new_page, vma, address);
87418+
87419+#ifdef CONFIG_PAX_SEGMEXEC
87420+ pax_mirror_huge_pte(vma, address, new_page);
87421+#endif
87422+
87423 /* Make the old page be freed below */
87424 new_page = old_page;
87425 }
87426@@ -2821,6 +2851,10 @@ retry:
87427 && (vma->vm_flags & VM_SHARED)));
87428 set_huge_pte_at(mm, address, ptep, new_pte);
87429
87430+#ifdef CONFIG_PAX_SEGMEXEC
87431+ pax_mirror_huge_pte(vma, address, page);
87432+#endif
87433+
87434 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
87435 /* Optimization, do the COW without a second fault */
87436 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
87437@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87438 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
87439 struct hstate *h = hstate_vma(vma);
87440
87441+#ifdef CONFIG_PAX_SEGMEXEC
87442+ struct vm_area_struct *vma_m;
87443+#endif
87444+
87445 address &= huge_page_mask(h);
87446
87447 ptep = huge_pte_offset(mm, address);
87448@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87449 VM_FAULT_SET_HINDEX(hstate_index(h));
87450 }
87451
87452+#ifdef CONFIG_PAX_SEGMEXEC
87453+ vma_m = pax_find_mirror_vma(vma);
87454+ if (vma_m) {
87455+ unsigned long address_m;
87456+
87457+ if (vma->vm_start > vma_m->vm_start) {
87458+ address_m = address;
87459+ address -= SEGMEXEC_TASK_SIZE;
87460+ vma = vma_m;
87461+ h = hstate_vma(vma);
87462+ } else
87463+ address_m = address + SEGMEXEC_TASK_SIZE;
87464+
87465+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
87466+ return VM_FAULT_OOM;
87467+ address_m &= HPAGE_MASK;
87468+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
87469+ }
87470+#endif
87471+
87472 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
87473 if (!ptep)
87474 return VM_FAULT_OOM;
87475diff --git a/mm/internal.h b/mm/internal.h
87476index 8562de0..92b2073 100644
87477--- a/mm/internal.h
87478+++ b/mm/internal.h
87479@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
87480 * in mm/page_alloc.c
87481 */
87482 extern void __free_pages_bootmem(struct page *page, unsigned int order);
87483+extern void free_compound_page(struct page *page);
87484 extern void prep_compound_page(struct page *page, unsigned long order);
87485 #ifdef CONFIG_MEMORY_FAILURE
87486 extern bool is_free_buddy_page(struct page *page);
87487@@ -355,7 +356,7 @@ extern u32 hwpoison_filter_enable;
87488
87489 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
87490 unsigned long, unsigned long,
87491- unsigned long, unsigned long);
87492+ unsigned long, unsigned long) __intentional_overflow(-1);
87493
87494 extern void set_pageblock_order(void);
87495 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
87496diff --git a/mm/kmemleak.c b/mm/kmemleak.c
87497index c8d7f31..2dbeffd 100644
87498--- a/mm/kmemleak.c
87499+++ b/mm/kmemleak.c
87500@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
87501
87502 for (i = 0; i < object->trace_len; i++) {
87503 void *ptr = (void *)object->trace[i];
87504- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
87505+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
87506 }
87507 }
87508
87509@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
87510 return -ENOMEM;
87511 }
87512
87513- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
87514+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
87515 &kmemleak_fops);
87516 if (!dentry)
87517 pr_warning("Failed to create the debugfs kmemleak file\n");
87518diff --git a/mm/maccess.c b/mm/maccess.c
87519index d53adf9..03a24bf 100644
87520--- a/mm/maccess.c
87521+++ b/mm/maccess.c
87522@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
87523 set_fs(KERNEL_DS);
87524 pagefault_disable();
87525 ret = __copy_from_user_inatomic(dst,
87526- (__force const void __user *)src, size);
87527+ (const void __force_user *)src, size);
87528 pagefault_enable();
87529 set_fs(old_fs);
87530
87531@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
87532
87533 set_fs(KERNEL_DS);
87534 pagefault_disable();
87535- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
87536+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
87537 pagefault_enable();
87538 set_fs(old_fs);
87539
87540diff --git a/mm/madvise.c b/mm/madvise.c
87541index 7055883..aafb1ed 100644
87542--- a/mm/madvise.c
87543+++ b/mm/madvise.c
87544@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
87545 pgoff_t pgoff;
87546 unsigned long new_flags = vma->vm_flags;
87547
87548+#ifdef CONFIG_PAX_SEGMEXEC
87549+ struct vm_area_struct *vma_m;
87550+#endif
87551+
87552 switch (behavior) {
87553 case MADV_NORMAL:
87554 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
87555@@ -126,6 +130,13 @@ success:
87556 /*
87557 * vm_flags is protected by the mmap_sem held in write mode.
87558 */
87559+
87560+#ifdef CONFIG_PAX_SEGMEXEC
87561+ vma_m = pax_find_mirror_vma(vma);
87562+ if (vma_m)
87563+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
87564+#endif
87565+
87566 vma->vm_flags = new_flags;
87567
87568 out:
87569@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
87570 struct vm_area_struct ** prev,
87571 unsigned long start, unsigned long end)
87572 {
87573+
87574+#ifdef CONFIG_PAX_SEGMEXEC
87575+ struct vm_area_struct *vma_m;
87576+#endif
87577+
87578 *prev = vma;
87579 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
87580 return -EINVAL;
87581@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
87582 zap_page_range(vma, start, end - start, &details);
87583 } else
87584 zap_page_range(vma, start, end - start, NULL);
87585+
87586+#ifdef CONFIG_PAX_SEGMEXEC
87587+ vma_m = pax_find_mirror_vma(vma);
87588+ if (vma_m) {
87589+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
87590+ struct zap_details details = {
87591+ .nonlinear_vma = vma_m,
87592+ .last_index = ULONG_MAX,
87593+ };
87594+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
87595+ } else
87596+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
87597+ }
87598+#endif
87599+
87600 return 0;
87601 }
87602
87603@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
87604 if (end < start)
87605 return error;
87606
87607+#ifdef CONFIG_PAX_SEGMEXEC
87608+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
87609+ if (end > SEGMEXEC_TASK_SIZE)
87610+ return error;
87611+ } else
87612+#endif
87613+
87614+ if (end > TASK_SIZE)
87615+ return error;
87616+
87617 error = 0;
87618 if (end == start)
87619 return error;
87620diff --git a/mm/memory-failure.c b/mm/memory-failure.c
87621index ceb0c7f..b2b8e94 100644
87622--- a/mm/memory-failure.c
87623+++ b/mm/memory-failure.c
87624@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
87625
87626 int sysctl_memory_failure_recovery __read_mostly = 1;
87627
87628-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87629+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87630
87631 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
87632
87633@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
87634 pfn, t->comm, t->pid);
87635 si.si_signo = SIGBUS;
87636 si.si_errno = 0;
87637- si.si_addr = (void *)addr;
87638+ si.si_addr = (void __user *)addr;
87639 #ifdef __ARCH_SI_TRAPNO
87640 si.si_trapno = trapno;
87641 #endif
87642@@ -760,7 +760,7 @@ static struct page_state {
87643 unsigned long res;
87644 char *msg;
87645 int (*action)(struct page *p, unsigned long pfn);
87646-} error_states[] = {
87647+} __do_const error_states[] = {
87648 { reserved, reserved, "reserved kernel", me_kernel },
87649 /*
87650 * free pages are specially detected outside this table:
87651@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87652 nr_pages = 1 << compound_order(hpage);
87653 else /* normal page or thp */
87654 nr_pages = 1;
87655- atomic_long_add(nr_pages, &num_poisoned_pages);
87656+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
87657
87658 /*
87659 * We need/can do nothing about count=0 pages.
87660@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87661 if (!PageHWPoison(hpage)
87662 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
87663 || (p != hpage && TestSetPageHWPoison(hpage))) {
87664- atomic_long_sub(nr_pages, &num_poisoned_pages);
87665+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87666 return 0;
87667 }
87668 set_page_hwpoison_huge_page(hpage);
87669@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87670 }
87671 if (hwpoison_filter(p)) {
87672 if (TestClearPageHWPoison(p))
87673- atomic_long_sub(nr_pages, &num_poisoned_pages);
87674+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87675 unlock_page(hpage);
87676 put_page(hpage);
87677 return 0;
87678@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
87679 return 0;
87680 }
87681 if (TestClearPageHWPoison(p))
87682- atomic_long_sub(nr_pages, &num_poisoned_pages);
87683+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87684 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
87685 return 0;
87686 }
87687@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
87688 */
87689 if (TestClearPageHWPoison(page)) {
87690 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
87691- atomic_long_sub(nr_pages, &num_poisoned_pages);
87692+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87693 freeit = 1;
87694 if (PageHuge(page))
87695 clear_page_hwpoison_huge_page(page);
87696@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
87697 } else {
87698 set_page_hwpoison_huge_page(hpage);
87699 dequeue_hwpoisoned_huge_page(hpage);
87700- atomic_long_add(1 << compound_trans_order(hpage),
87701+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
87702 &num_poisoned_pages);
87703 }
87704 /* keep elevated page count for bad page */
87705@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
87706 if (PageHuge(page)) {
87707 set_page_hwpoison_huge_page(hpage);
87708 dequeue_hwpoisoned_huge_page(hpage);
87709- atomic_long_add(1 << compound_trans_order(hpage),
87710+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
87711 &num_poisoned_pages);
87712 } else {
87713 SetPageHWPoison(page);
87714- atomic_long_inc(&num_poisoned_pages);
87715+ atomic_long_inc_unchecked(&num_poisoned_pages);
87716 }
87717 }
87718 /* keep elevated page count for bad page */
87719@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
87720 put_page(page);
87721 pr_info("soft_offline: %#lx: invalidated\n", pfn);
87722 SetPageHWPoison(page);
87723- atomic_long_inc(&num_poisoned_pages);
87724+ atomic_long_inc_unchecked(&num_poisoned_pages);
87725 return 0;
87726 }
87727
87728@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
87729 ret = -EIO;
87730 } else {
87731 SetPageHWPoison(page);
87732- atomic_long_inc(&num_poisoned_pages);
87733+ atomic_long_inc_unchecked(&num_poisoned_pages);
87734 }
87735 } else {
87736 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
87737diff --git a/mm/memory.c b/mm/memory.c
87738index 5a35443..7c0340f 100644
87739--- a/mm/memory.c
87740+++ b/mm/memory.c
87741@@ -428,6 +428,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87742 free_pte_range(tlb, pmd, addr);
87743 } while (pmd++, addr = next, addr != end);
87744
87745+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
87746 start &= PUD_MASK;
87747 if (start < floor)
87748 return;
87749@@ -442,6 +443,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87750 pmd = pmd_offset(pud, start);
87751 pud_clear(pud);
87752 pmd_free_tlb(tlb, pmd, start);
87753+#endif
87754+
87755 }
87756
87757 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87758@@ -461,6 +464,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87759 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
87760 } while (pud++, addr = next, addr != end);
87761
87762+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
87763 start &= PGDIR_MASK;
87764 if (start < floor)
87765 return;
87766@@ -475,6 +479,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87767 pud = pud_offset(pgd, start);
87768 pgd_clear(pgd);
87769 pud_free_tlb(tlb, pud, start);
87770+#endif
87771+
87772 }
87773
87774 /*
87775@@ -1644,12 +1650,6 @@ no_page_table:
87776 return page;
87777 }
87778
87779-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
87780-{
87781- return stack_guard_page_start(vma, addr) ||
87782- stack_guard_page_end(vma, addr+PAGE_SIZE);
87783-}
87784-
87785 /**
87786 * __get_user_pages() - pin user pages in memory
87787 * @tsk: task_struct of target task
87788@@ -1736,10 +1736,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87789
87790 i = 0;
87791
87792- do {
87793+ while (nr_pages) {
87794 struct vm_area_struct *vma;
87795
87796- vma = find_extend_vma(mm, start);
87797+ vma = find_vma(mm, start);
87798 if (!vma && in_gate_area(mm, start)) {
87799 unsigned long pg = start & PAGE_MASK;
87800 pgd_t *pgd;
87801@@ -1788,7 +1788,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87802 goto next_page;
87803 }
87804
87805- if (!vma ||
87806+ if (!vma || start < vma->vm_start ||
87807 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
87808 !(vm_flags & vma->vm_flags))
87809 return i ? : -EFAULT;
87810@@ -1817,11 +1817,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87811 int ret;
87812 unsigned int fault_flags = 0;
87813
87814- /* For mlock, just skip the stack guard page. */
87815- if (foll_flags & FOLL_MLOCK) {
87816- if (stack_guard_page(vma, start))
87817- goto next_page;
87818- }
87819 if (foll_flags & FOLL_WRITE)
87820 fault_flags |= FAULT_FLAG_WRITE;
87821 if (nonblocking)
87822@@ -1901,7 +1896,7 @@ next_page:
87823 start += page_increm * PAGE_SIZE;
87824 nr_pages -= page_increm;
87825 } while (nr_pages && start < vma->vm_end);
87826- } while (nr_pages);
87827+ }
87828 return i;
87829 }
87830 EXPORT_SYMBOL(__get_user_pages);
87831@@ -2108,6 +2103,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
87832 page_add_file_rmap(page);
87833 set_pte_at(mm, addr, pte, mk_pte(page, prot));
87834
87835+#ifdef CONFIG_PAX_SEGMEXEC
87836+ pax_mirror_file_pte(vma, addr, page, ptl);
87837+#endif
87838+
87839 retval = 0;
87840 pte_unmap_unlock(pte, ptl);
87841 return retval;
87842@@ -2152,9 +2151,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
87843 if (!page_count(page))
87844 return -EINVAL;
87845 if (!(vma->vm_flags & VM_MIXEDMAP)) {
87846+
87847+#ifdef CONFIG_PAX_SEGMEXEC
87848+ struct vm_area_struct *vma_m;
87849+#endif
87850+
87851 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
87852 BUG_ON(vma->vm_flags & VM_PFNMAP);
87853 vma->vm_flags |= VM_MIXEDMAP;
87854+
87855+#ifdef CONFIG_PAX_SEGMEXEC
87856+ vma_m = pax_find_mirror_vma(vma);
87857+ if (vma_m)
87858+ vma_m->vm_flags |= VM_MIXEDMAP;
87859+#endif
87860+
87861 }
87862 return insert_page(vma, addr, page, vma->vm_page_prot);
87863 }
87864@@ -2237,6 +2248,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
87865 unsigned long pfn)
87866 {
87867 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
87868+ BUG_ON(vma->vm_mirror);
87869
87870 if (addr < vma->vm_start || addr >= vma->vm_end)
87871 return -EFAULT;
87872@@ -2484,7 +2496,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
87873
87874 BUG_ON(pud_huge(*pud));
87875
87876- pmd = pmd_alloc(mm, pud, addr);
87877+ pmd = (mm == &init_mm) ?
87878+ pmd_alloc_kernel(mm, pud, addr) :
87879+ pmd_alloc(mm, pud, addr);
87880 if (!pmd)
87881 return -ENOMEM;
87882 do {
87883@@ -2504,7 +2518,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
87884 unsigned long next;
87885 int err;
87886
87887- pud = pud_alloc(mm, pgd, addr);
87888+ pud = (mm == &init_mm) ?
87889+ pud_alloc_kernel(mm, pgd, addr) :
87890+ pud_alloc(mm, pgd, addr);
87891 if (!pud)
87892 return -ENOMEM;
87893 do {
87894@@ -2592,6 +2608,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
87895 copy_user_highpage(dst, src, va, vma);
87896 }
87897
87898+#ifdef CONFIG_PAX_SEGMEXEC
87899+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
87900+{
87901+ struct mm_struct *mm = vma->vm_mm;
87902+ spinlock_t *ptl;
87903+ pte_t *pte, entry;
87904+
87905+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
87906+ entry = *pte;
87907+ if (!pte_present(entry)) {
87908+ if (!pte_none(entry)) {
87909+ BUG_ON(pte_file(entry));
87910+ free_swap_and_cache(pte_to_swp_entry(entry));
87911+ pte_clear_not_present_full(mm, address, pte, 0);
87912+ }
87913+ } else {
87914+ struct page *page;
87915+
87916+ flush_cache_page(vma, address, pte_pfn(entry));
87917+ entry = ptep_clear_flush(vma, address, pte);
87918+ BUG_ON(pte_dirty(entry));
87919+ page = vm_normal_page(vma, address, entry);
87920+ if (page) {
87921+ update_hiwater_rss(mm);
87922+ if (PageAnon(page))
87923+ dec_mm_counter_fast(mm, MM_ANONPAGES);
87924+ else
87925+ dec_mm_counter_fast(mm, MM_FILEPAGES);
87926+ page_remove_rmap(page);
87927+ page_cache_release(page);
87928+ }
87929+ }
87930+ pte_unmap_unlock(pte, ptl);
87931+}
87932+
87933+/* PaX: if vma is mirrored, synchronize the mirror's PTE
87934+ *
87935+ * the ptl of the lower mapped page is held on entry and is not released on exit
87936+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
87937+ */
87938+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
87939+{
87940+ struct mm_struct *mm = vma->vm_mm;
87941+ unsigned long address_m;
87942+ spinlock_t *ptl_m;
87943+ struct vm_area_struct *vma_m;
87944+ pmd_t *pmd_m;
87945+ pte_t *pte_m, entry_m;
87946+
87947+ BUG_ON(!page_m || !PageAnon(page_m));
87948+
87949+ vma_m = pax_find_mirror_vma(vma);
87950+ if (!vma_m)
87951+ return;
87952+
87953+ BUG_ON(!PageLocked(page_m));
87954+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87955+ address_m = address + SEGMEXEC_TASK_SIZE;
87956+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87957+ pte_m = pte_offset_map(pmd_m, address_m);
87958+ ptl_m = pte_lockptr(mm, pmd_m);
87959+ if (ptl != ptl_m) {
87960+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87961+ if (!pte_none(*pte_m))
87962+ goto out;
87963+ }
87964+
87965+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
87966+ page_cache_get(page_m);
87967+ page_add_anon_rmap(page_m, vma_m, address_m);
87968+ inc_mm_counter_fast(mm, MM_ANONPAGES);
87969+ set_pte_at(mm, address_m, pte_m, entry_m);
87970+ update_mmu_cache(vma_m, address_m, pte_m);
87971+out:
87972+ if (ptl != ptl_m)
87973+ spin_unlock(ptl_m);
87974+ pte_unmap(pte_m);
87975+ unlock_page(page_m);
87976+}
87977+
87978+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
87979+{
87980+ struct mm_struct *mm = vma->vm_mm;
87981+ unsigned long address_m;
87982+ spinlock_t *ptl_m;
87983+ struct vm_area_struct *vma_m;
87984+ pmd_t *pmd_m;
87985+ pte_t *pte_m, entry_m;
87986+
87987+ BUG_ON(!page_m || PageAnon(page_m));
87988+
87989+ vma_m = pax_find_mirror_vma(vma);
87990+ if (!vma_m)
87991+ return;
87992+
87993+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87994+ address_m = address + SEGMEXEC_TASK_SIZE;
87995+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87996+ pte_m = pte_offset_map(pmd_m, address_m);
87997+ ptl_m = pte_lockptr(mm, pmd_m);
87998+ if (ptl != ptl_m) {
87999+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88000+ if (!pte_none(*pte_m))
88001+ goto out;
88002+ }
88003+
88004+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
88005+ page_cache_get(page_m);
88006+ page_add_file_rmap(page_m);
88007+ inc_mm_counter_fast(mm, MM_FILEPAGES);
88008+ set_pte_at(mm, address_m, pte_m, entry_m);
88009+ update_mmu_cache(vma_m, address_m, pte_m);
88010+out:
88011+ if (ptl != ptl_m)
88012+ spin_unlock(ptl_m);
88013+ pte_unmap(pte_m);
88014+}
88015+
88016+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
88017+{
88018+ struct mm_struct *mm = vma->vm_mm;
88019+ unsigned long address_m;
88020+ spinlock_t *ptl_m;
88021+ struct vm_area_struct *vma_m;
88022+ pmd_t *pmd_m;
88023+ pte_t *pte_m, entry_m;
88024+
88025+ vma_m = pax_find_mirror_vma(vma);
88026+ if (!vma_m)
88027+ return;
88028+
88029+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
88030+ address_m = address + SEGMEXEC_TASK_SIZE;
88031+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
88032+ pte_m = pte_offset_map(pmd_m, address_m);
88033+ ptl_m = pte_lockptr(mm, pmd_m);
88034+ if (ptl != ptl_m) {
88035+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
88036+ if (!pte_none(*pte_m))
88037+ goto out;
88038+ }
88039+
88040+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
88041+ set_pte_at(mm, address_m, pte_m, entry_m);
88042+out:
88043+ if (ptl != ptl_m)
88044+ spin_unlock(ptl_m);
88045+ pte_unmap(pte_m);
88046+}
88047+
88048+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
88049+{
88050+ struct page *page_m;
88051+ pte_t entry;
88052+
88053+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
88054+ goto out;
88055+
88056+ entry = *pte;
88057+ page_m = vm_normal_page(vma, address, entry);
88058+ if (!page_m)
88059+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
88060+ else if (PageAnon(page_m)) {
88061+ if (pax_find_mirror_vma(vma)) {
88062+ pte_unmap_unlock(pte, ptl);
88063+ lock_page(page_m);
88064+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
88065+ if (pte_same(entry, *pte))
88066+ pax_mirror_anon_pte(vma, address, page_m, ptl);
88067+ else
88068+ unlock_page(page_m);
88069+ }
88070+ } else
88071+ pax_mirror_file_pte(vma, address, page_m, ptl);
88072+
88073+out:
88074+ pte_unmap_unlock(pte, ptl);
88075+}
88076+#endif
88077+
88078 /*
88079 * This routine handles present pages, when users try to write
88080 * to a shared page. It is done by copying the page to a new address
88081@@ -2808,6 +3004,12 @@ gotten:
88082 */
88083 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88084 if (likely(pte_same(*page_table, orig_pte))) {
88085+
88086+#ifdef CONFIG_PAX_SEGMEXEC
88087+ if (pax_find_mirror_vma(vma))
88088+ BUG_ON(!trylock_page(new_page));
88089+#endif
88090+
88091 if (old_page) {
88092 if (!PageAnon(old_page)) {
88093 dec_mm_counter_fast(mm, MM_FILEPAGES);
88094@@ -2859,6 +3061,10 @@ gotten:
88095 page_remove_rmap(old_page);
88096 }
88097
88098+#ifdef CONFIG_PAX_SEGMEXEC
88099+ pax_mirror_anon_pte(vma, address, new_page, ptl);
88100+#endif
88101+
88102 /* Free the old page.. */
88103 new_page = old_page;
88104 ret |= VM_FAULT_WRITE;
88105@@ -3134,6 +3340,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
88106 swap_free(entry);
88107 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
88108 try_to_free_swap(page);
88109+
88110+#ifdef CONFIG_PAX_SEGMEXEC
88111+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
88112+#endif
88113+
88114 unlock_page(page);
88115 if (page != swapcache) {
88116 /*
88117@@ -3157,6 +3368,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
88118
88119 /* No need to invalidate - it was non-present before */
88120 update_mmu_cache(vma, address, page_table);
88121+
88122+#ifdef CONFIG_PAX_SEGMEXEC
88123+ pax_mirror_anon_pte(vma, address, page, ptl);
88124+#endif
88125+
88126 unlock:
88127 pte_unmap_unlock(page_table, ptl);
88128 out:
88129@@ -3176,40 +3392,6 @@ out_release:
88130 }
88131
88132 /*
88133- * This is like a special single-page "expand_{down|up}wards()",
88134- * except we must first make sure that 'address{-|+}PAGE_SIZE'
88135- * doesn't hit another vma.
88136- */
88137-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
88138-{
88139- address &= PAGE_MASK;
88140- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
88141- struct vm_area_struct *prev = vma->vm_prev;
88142-
88143- /*
88144- * Is there a mapping abutting this one below?
88145- *
88146- * That's only ok if it's the same stack mapping
88147- * that has gotten split..
88148- */
88149- if (prev && prev->vm_end == address)
88150- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
88151-
88152- expand_downwards(vma, address - PAGE_SIZE);
88153- }
88154- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
88155- struct vm_area_struct *next = vma->vm_next;
88156-
88157- /* As VM_GROWSDOWN but s/below/above/ */
88158- if (next && next->vm_start == address + PAGE_SIZE)
88159- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
88160-
88161- expand_upwards(vma, address + PAGE_SIZE);
88162- }
88163- return 0;
88164-}
88165-
88166-/*
88167 * We enter with non-exclusive mmap_sem (to exclude vma changes,
88168 * but allow concurrent faults), and pte mapped but not yet locked.
88169 * We return with mmap_sem still held, but pte unmapped and unlocked.
88170@@ -3218,27 +3400,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
88171 unsigned long address, pte_t *page_table, pmd_t *pmd,
88172 unsigned int flags)
88173 {
88174- struct page *page;
88175+ struct page *page = NULL;
88176 spinlock_t *ptl;
88177 pte_t entry;
88178
88179- pte_unmap(page_table);
88180-
88181- /* Check if we need to add a guard page to the stack */
88182- if (check_stack_guard_page(vma, address) < 0)
88183- return VM_FAULT_SIGBUS;
88184-
88185- /* Use the zero-page for reads */
88186 if (!(flags & FAULT_FLAG_WRITE)) {
88187 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
88188 vma->vm_page_prot));
88189- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
88190+ ptl = pte_lockptr(mm, pmd);
88191+ spin_lock(ptl);
88192 if (!pte_none(*page_table))
88193 goto unlock;
88194 goto setpte;
88195 }
88196
88197 /* Allocate our own private page. */
88198+ pte_unmap(page_table);
88199+
88200 if (unlikely(anon_vma_prepare(vma)))
88201 goto oom;
88202 page = alloc_zeroed_user_highpage_movable(vma, address);
88203@@ -3262,6 +3440,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
88204 if (!pte_none(*page_table))
88205 goto release;
88206
88207+#ifdef CONFIG_PAX_SEGMEXEC
88208+ if (pax_find_mirror_vma(vma))
88209+ BUG_ON(!trylock_page(page));
88210+#endif
88211+
88212 inc_mm_counter_fast(mm, MM_ANONPAGES);
88213 page_add_new_anon_rmap(page, vma, address);
88214 setpte:
88215@@ -3269,6 +3452,12 @@ setpte:
88216
88217 /* No need to invalidate - it was non-present before */
88218 update_mmu_cache(vma, address, page_table);
88219+
88220+#ifdef CONFIG_PAX_SEGMEXEC
88221+ if (page)
88222+ pax_mirror_anon_pte(vma, address, page, ptl);
88223+#endif
88224+
88225 unlock:
88226 pte_unmap_unlock(page_table, ptl);
88227 return 0;
88228@@ -3412,6 +3601,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88229 */
88230 /* Only go through if we didn't race with anybody else... */
88231 if (likely(pte_same(*page_table, orig_pte))) {
88232+
88233+#ifdef CONFIG_PAX_SEGMEXEC
88234+ if (anon && pax_find_mirror_vma(vma))
88235+ BUG_ON(!trylock_page(page));
88236+#endif
88237+
88238 flush_icache_page(vma, page);
88239 entry = mk_pte(page, vma->vm_page_prot);
88240 if (flags & FAULT_FLAG_WRITE)
88241@@ -3431,6 +3626,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88242
88243 /* no need to invalidate: a not-present page won't be cached */
88244 update_mmu_cache(vma, address, page_table);
88245+
88246+#ifdef CONFIG_PAX_SEGMEXEC
88247+ if (anon)
88248+ pax_mirror_anon_pte(vma, address, page, ptl);
88249+ else
88250+ pax_mirror_file_pte(vma, address, page, ptl);
88251+#endif
88252+
88253 } else {
88254 if (cow_page)
88255 mem_cgroup_uncharge_page(cow_page);
88256@@ -3752,6 +3955,12 @@ int handle_pte_fault(struct mm_struct *mm,
88257 if (flags & FAULT_FLAG_WRITE)
88258 flush_tlb_fix_spurious_fault(vma, address);
88259 }
88260+
88261+#ifdef CONFIG_PAX_SEGMEXEC
88262+ pax_mirror_pte(vma, address, pte, pmd, ptl);
88263+ return 0;
88264+#endif
88265+
88266 unlock:
88267 pte_unmap_unlock(pte, ptl);
88268 return 0;
88269@@ -3768,6 +3977,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88270 pmd_t *pmd;
88271 pte_t *pte;
88272
88273+#ifdef CONFIG_PAX_SEGMEXEC
88274+ struct vm_area_struct *vma_m;
88275+#endif
88276+
88277 __set_current_state(TASK_RUNNING);
88278
88279 count_vm_event(PGFAULT);
88280@@ -3779,6 +3992,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88281 if (unlikely(is_vm_hugetlb_page(vma)))
88282 return hugetlb_fault(mm, vma, address, flags);
88283
88284+#ifdef CONFIG_PAX_SEGMEXEC
88285+ vma_m = pax_find_mirror_vma(vma);
88286+ if (vma_m) {
88287+ unsigned long address_m;
88288+ pgd_t *pgd_m;
88289+ pud_t *pud_m;
88290+ pmd_t *pmd_m;
88291+
88292+ if (vma->vm_start > vma_m->vm_start) {
88293+ address_m = address;
88294+ address -= SEGMEXEC_TASK_SIZE;
88295+ vma = vma_m;
88296+ } else
88297+ address_m = address + SEGMEXEC_TASK_SIZE;
88298+
88299+ pgd_m = pgd_offset(mm, address_m);
88300+ pud_m = pud_alloc(mm, pgd_m, address_m);
88301+ if (!pud_m)
88302+ return VM_FAULT_OOM;
88303+ pmd_m = pmd_alloc(mm, pud_m, address_m);
88304+ if (!pmd_m)
88305+ return VM_FAULT_OOM;
88306+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
88307+ return VM_FAULT_OOM;
88308+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
88309+ }
88310+#endif
88311+
88312 retry:
88313 pgd = pgd_offset(mm, address);
88314 pud = pud_alloc(mm, pgd, address);
88315@@ -3877,6 +4118,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88316 spin_unlock(&mm->page_table_lock);
88317 return 0;
88318 }
88319+
88320+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88321+{
88322+ pud_t *new = pud_alloc_one(mm, address);
88323+ if (!new)
88324+ return -ENOMEM;
88325+
88326+ smp_wmb(); /* See comment in __pte_alloc */
88327+
88328+ spin_lock(&mm->page_table_lock);
88329+ if (pgd_present(*pgd)) /* Another has populated it */
88330+ pud_free(mm, new);
88331+ else
88332+ pgd_populate_kernel(mm, pgd, new);
88333+ spin_unlock(&mm->page_table_lock);
88334+ return 0;
88335+}
88336 #endif /* __PAGETABLE_PUD_FOLDED */
88337
88338 #ifndef __PAGETABLE_PMD_FOLDED
88339@@ -3907,6 +4165,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
88340 spin_unlock(&mm->page_table_lock);
88341 return 0;
88342 }
88343+
88344+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
88345+{
88346+ pmd_t *new = pmd_alloc_one(mm, address);
88347+ if (!new)
88348+ return -ENOMEM;
88349+
88350+ smp_wmb(); /* See comment in __pte_alloc */
88351+
88352+ spin_lock(&mm->page_table_lock);
88353+#ifndef __ARCH_HAS_4LEVEL_HACK
88354+ if (pud_present(*pud)) /* Another has populated it */
88355+ pmd_free(mm, new);
88356+ else
88357+ pud_populate_kernel(mm, pud, new);
88358+#else
88359+ if (pgd_present(*pud)) /* Another has populated it */
88360+ pmd_free(mm, new);
88361+ else
88362+ pgd_populate_kernel(mm, pud, new);
88363+#endif /* __ARCH_HAS_4LEVEL_HACK */
88364+ spin_unlock(&mm->page_table_lock);
88365+ return 0;
88366+}
88367 #endif /* __PAGETABLE_PMD_FOLDED */
88368
88369 #if !defined(__HAVE_ARCH_GATE_AREA)
88370@@ -3920,7 +4202,7 @@ static int __init gate_vma_init(void)
88371 gate_vma.vm_start = FIXADDR_USER_START;
88372 gate_vma.vm_end = FIXADDR_USER_END;
88373 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
88374- gate_vma.vm_page_prot = __P101;
88375+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
88376
88377 return 0;
88378 }
88379@@ -4054,8 +4336,8 @@ out:
88380 return ret;
88381 }
88382
88383-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88384- void *buf, int len, int write)
88385+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88386+ void *buf, size_t len, int write)
88387 {
88388 resource_size_t phys_addr;
88389 unsigned long prot = 0;
88390@@ -4080,8 +4362,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88391 * Access another process' address space as given in mm. If non-NULL, use the
88392 * given task for page fault accounting.
88393 */
88394-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88395- unsigned long addr, void *buf, int len, int write)
88396+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88397+ unsigned long addr, void *buf, size_t len, int write)
88398 {
88399 struct vm_area_struct *vma;
88400 void *old_buf = buf;
88401@@ -4089,7 +4371,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88402 down_read(&mm->mmap_sem);
88403 /* ignore errors, just check how much was successfully transferred */
88404 while (len) {
88405- int bytes, ret, offset;
88406+ ssize_t bytes, ret, offset;
88407 void *maddr;
88408 struct page *page = NULL;
88409
88410@@ -4148,8 +4430,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88411 *
88412 * The caller must hold a reference on @mm.
88413 */
88414-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88415- void *buf, int len, int write)
88416+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88417+ void *buf, size_t len, int write)
88418 {
88419 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88420 }
88421@@ -4159,11 +4441,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88422 * Source/target buffer must be kernel space,
88423 * Do not walk the page table directly, use get_user_pages
88424 */
88425-int access_process_vm(struct task_struct *tsk, unsigned long addr,
88426- void *buf, int len, int write)
88427+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
88428+ void *buf, size_t len, int write)
88429 {
88430 struct mm_struct *mm;
88431- int ret;
88432+ ssize_t ret;
88433
88434 mm = get_task_mm(tsk);
88435 if (!mm)
88436diff --git a/mm/mempolicy.c b/mm/mempolicy.c
88437index 4baf12e..5497066 100644
88438--- a/mm/mempolicy.c
88439+++ b/mm/mempolicy.c
88440@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88441 unsigned long vmstart;
88442 unsigned long vmend;
88443
88444+#ifdef CONFIG_PAX_SEGMEXEC
88445+ struct vm_area_struct *vma_m;
88446+#endif
88447+
88448 vma = find_vma(mm, start);
88449 if (!vma || vma->vm_start > start)
88450 return -EFAULT;
88451@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88452 err = vma_replace_policy(vma, new_pol);
88453 if (err)
88454 goto out;
88455+
88456+#ifdef CONFIG_PAX_SEGMEXEC
88457+ vma_m = pax_find_mirror_vma(vma);
88458+ if (vma_m) {
88459+ err = vma_replace_policy(vma_m, new_pol);
88460+ if (err)
88461+ goto out;
88462+ }
88463+#endif
88464+
88465 }
88466
88467 out:
88468@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
88469
88470 if (end < start)
88471 return -EINVAL;
88472+
88473+#ifdef CONFIG_PAX_SEGMEXEC
88474+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88475+ if (end > SEGMEXEC_TASK_SIZE)
88476+ return -EINVAL;
88477+ } else
88478+#endif
88479+
88480+ if (end > TASK_SIZE)
88481+ return -EINVAL;
88482+
88483 if (end == start)
88484 return 0;
88485
88486@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88487 */
88488 tcred = __task_cred(task);
88489 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88490- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88491- !capable(CAP_SYS_NICE)) {
88492+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88493 rcu_read_unlock();
88494 err = -EPERM;
88495 goto out_put;
88496@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88497 goto out;
88498 }
88499
88500+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
88501+ if (mm != current->mm &&
88502+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
88503+ mmput(mm);
88504+ err = -EPERM;
88505+ goto out;
88506+ }
88507+#endif
88508+
88509 err = do_migrate_pages(mm, old, new,
88510 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
88511
88512diff --git a/mm/migrate.c b/mm/migrate.c
88513index 6f0c244..6d1ae32 100644
88514--- a/mm/migrate.c
88515+++ b/mm/migrate.c
88516@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
88517 */
88518 tcred = __task_cred(task);
88519 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88520- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88521- !capable(CAP_SYS_NICE)) {
88522+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88523 rcu_read_unlock();
88524 err = -EPERM;
88525 goto out;
88526diff --git a/mm/mlock.c b/mm/mlock.c
88527index 79b7cf7..9944291 100644
88528--- a/mm/mlock.c
88529+++ b/mm/mlock.c
88530@@ -13,6 +13,7 @@
88531 #include <linux/pagemap.h>
88532 #include <linux/mempolicy.h>
88533 #include <linux/syscalls.h>
88534+#include <linux/security.h>
88535 #include <linux/sched.h>
88536 #include <linux/export.h>
88537 #include <linux/rmap.h>
88538@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
88539 {
88540 unsigned long nstart, end, tmp;
88541 struct vm_area_struct * vma, * prev;
88542- int error;
88543+ int error = 0;
88544
88545 VM_BUG_ON(start & ~PAGE_MASK);
88546 VM_BUG_ON(len != PAGE_ALIGN(len));
88547@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
88548 return -EINVAL;
88549 if (end == start)
88550 return 0;
88551+ if (end > TASK_SIZE)
88552+ return -EINVAL;
88553+
88554 vma = find_vma(current->mm, start);
88555 if (!vma || vma->vm_start > start)
88556 return -ENOMEM;
88557@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
88558 for (nstart = start ; ; ) {
88559 vm_flags_t newflags;
88560
88561+#ifdef CONFIG_PAX_SEGMEXEC
88562+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88563+ break;
88564+#endif
88565+
88566 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
88567
88568 newflags = vma->vm_flags & ~VM_LOCKED;
88569@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
88570 lock_limit >>= PAGE_SHIFT;
88571
88572 /* check against resource limits */
88573+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
88574 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
88575 error = do_mlock(start, len, 1);
88576 up_write(&current->mm->mmap_sem);
88577@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
88578 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
88579 vm_flags_t newflags;
88580
88581+#ifdef CONFIG_PAX_SEGMEXEC
88582+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88583+ break;
88584+#endif
88585+
88586 newflags = vma->vm_flags & ~VM_LOCKED;
88587 if (flags & MCL_CURRENT)
88588 newflags |= VM_LOCKED;
88589@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
88590 lock_limit >>= PAGE_SHIFT;
88591
88592 ret = -ENOMEM;
88593+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
88594 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
88595 capable(CAP_IPC_LOCK))
88596 ret = do_mlockall(flags);
88597diff --git a/mm/mmap.c b/mm/mmap.c
88598index 8d25fdc..bfb7626 100644
88599--- a/mm/mmap.c
88600+++ b/mm/mmap.c
88601@@ -36,6 +36,7 @@
88602 #include <linux/sched/sysctl.h>
88603 #include <linux/notifier.h>
88604 #include <linux/memory.h>
88605+#include <linux/random.h>
88606
88607 #include <asm/uaccess.h>
88608 #include <asm/cacheflush.h>
88609@@ -52,6 +53,16 @@
88610 #define arch_rebalance_pgtables(addr, len) (addr)
88611 #endif
88612
88613+static inline void verify_mm_writelocked(struct mm_struct *mm)
88614+{
88615+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
88616+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88617+ up_read(&mm->mmap_sem);
88618+ BUG();
88619+ }
88620+#endif
88621+}
88622+
88623 static void unmap_region(struct mm_struct *mm,
88624 struct vm_area_struct *vma, struct vm_area_struct *prev,
88625 unsigned long start, unsigned long end);
88626@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
88627 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
88628 *
88629 */
88630-pgprot_t protection_map[16] = {
88631+pgprot_t protection_map[16] __read_only = {
88632 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
88633 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
88634 };
88635
88636-pgprot_t vm_get_page_prot(unsigned long vm_flags)
88637+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
88638 {
88639- return __pgprot(pgprot_val(protection_map[vm_flags &
88640+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
88641 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
88642 pgprot_val(arch_vm_get_page_prot(vm_flags)));
88643+
88644+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88645+ if (!(__supported_pte_mask & _PAGE_NX) &&
88646+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
88647+ (vm_flags & (VM_READ | VM_WRITE)))
88648+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
88649+#endif
88650+
88651+ return prot;
88652 }
88653 EXPORT_SYMBOL(vm_get_page_prot);
88654
88655@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
88656 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
88657 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88658 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88659+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
88660 /*
88661 * Make sure vm_committed_as in one cacheline and not cacheline shared with
88662 * other variables. It can be updated by several CPUs frequently.
88663@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
88664 struct vm_area_struct *next = vma->vm_next;
88665
88666 might_sleep();
88667+ BUG_ON(vma->vm_mirror);
88668 if (vma->vm_ops && vma->vm_ops->close)
88669 vma->vm_ops->close(vma);
88670 if (vma->vm_file)
88671@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
88672 * not page aligned -Ram Gupta
88673 */
88674 rlim = rlimit(RLIMIT_DATA);
88675+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
88676 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
88677 (mm->end_data - mm->start_data) > rlim)
88678 goto out;
88679@@ -933,6 +956,12 @@ static int
88680 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
88681 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88682 {
88683+
88684+#ifdef CONFIG_PAX_SEGMEXEC
88685+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
88686+ return 0;
88687+#endif
88688+
88689 if (is_mergeable_vma(vma, file, vm_flags) &&
88690 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88691 if (vma->vm_pgoff == vm_pgoff)
88692@@ -952,6 +981,12 @@ static int
88693 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88694 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88695 {
88696+
88697+#ifdef CONFIG_PAX_SEGMEXEC
88698+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
88699+ return 0;
88700+#endif
88701+
88702 if (is_mergeable_vma(vma, file, vm_flags) &&
88703 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88704 pgoff_t vm_pglen;
88705@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88706 struct vm_area_struct *vma_merge(struct mm_struct *mm,
88707 struct vm_area_struct *prev, unsigned long addr,
88708 unsigned long end, unsigned long vm_flags,
88709- struct anon_vma *anon_vma, struct file *file,
88710+ struct anon_vma *anon_vma, struct file *file,
88711 pgoff_t pgoff, struct mempolicy *policy)
88712 {
88713 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
88714 struct vm_area_struct *area, *next;
88715 int err;
88716
88717+#ifdef CONFIG_PAX_SEGMEXEC
88718+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
88719+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
88720+
88721+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
88722+#endif
88723+
88724 /*
88725 * We later require that vma->vm_flags == vm_flags,
88726 * so this tests vma->vm_flags & VM_SPECIAL, too.
88727@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88728 if (next && next->vm_end == end) /* cases 6, 7, 8 */
88729 next = next->vm_next;
88730
88731+#ifdef CONFIG_PAX_SEGMEXEC
88732+ if (prev)
88733+ prev_m = pax_find_mirror_vma(prev);
88734+ if (area)
88735+ area_m = pax_find_mirror_vma(area);
88736+ if (next)
88737+ next_m = pax_find_mirror_vma(next);
88738+#endif
88739+
88740 /*
88741 * Can it merge with the predecessor?
88742 */
88743@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88744 /* cases 1, 6 */
88745 err = vma_adjust(prev, prev->vm_start,
88746 next->vm_end, prev->vm_pgoff, NULL);
88747- } else /* cases 2, 5, 7 */
88748+
88749+#ifdef CONFIG_PAX_SEGMEXEC
88750+ if (!err && prev_m)
88751+ err = vma_adjust(prev_m, prev_m->vm_start,
88752+ next_m->vm_end, prev_m->vm_pgoff, NULL);
88753+#endif
88754+
88755+ } else { /* cases 2, 5, 7 */
88756 err = vma_adjust(prev, prev->vm_start,
88757 end, prev->vm_pgoff, NULL);
88758+
88759+#ifdef CONFIG_PAX_SEGMEXEC
88760+ if (!err && prev_m)
88761+ err = vma_adjust(prev_m, prev_m->vm_start,
88762+ end_m, prev_m->vm_pgoff, NULL);
88763+#endif
88764+
88765+ }
88766 if (err)
88767 return NULL;
88768 khugepaged_enter_vma_merge(prev);
88769@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88770 mpol_equal(policy, vma_policy(next)) &&
88771 can_vma_merge_before(next, vm_flags,
88772 anon_vma, file, pgoff+pglen)) {
88773- if (prev && addr < prev->vm_end) /* case 4 */
88774+ if (prev && addr < prev->vm_end) { /* case 4 */
88775 err = vma_adjust(prev, prev->vm_start,
88776 addr, prev->vm_pgoff, NULL);
88777- else /* cases 3, 8 */
88778+
88779+#ifdef CONFIG_PAX_SEGMEXEC
88780+ if (!err && prev_m)
88781+ err = vma_adjust(prev_m, prev_m->vm_start,
88782+ addr_m, prev_m->vm_pgoff, NULL);
88783+#endif
88784+
88785+ } else { /* cases 3, 8 */
88786 err = vma_adjust(area, addr, next->vm_end,
88787 next->vm_pgoff - pglen, NULL);
88788+
88789+#ifdef CONFIG_PAX_SEGMEXEC
88790+ if (!err && area_m)
88791+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
88792+ next_m->vm_pgoff - pglen, NULL);
88793+#endif
88794+
88795+ }
88796 if (err)
88797 return NULL;
88798 khugepaged_enter_vma_merge(area);
88799@@ -1165,8 +1246,10 @@ none:
88800 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88801 struct file *file, long pages)
88802 {
88803- const unsigned long stack_flags
88804- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
88805+
88806+#ifdef CONFIG_PAX_RANDMMAP
88807+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88808+#endif
88809
88810 mm->total_vm += pages;
88811
88812@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88813 mm->shared_vm += pages;
88814 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
88815 mm->exec_vm += pages;
88816- } else if (flags & stack_flags)
88817+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
88818 mm->stack_vm += pages;
88819 }
88820 #endif /* CONFIG_PROC_FS */
88821@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88822 * (the exception is when the underlying filesystem is noexec
88823 * mounted, in which case we dont add PROT_EXEC.)
88824 */
88825- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88826+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88827 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
88828 prot |= PROT_EXEC;
88829
88830@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88831 /* Obtain the address to map to. we verify (or select) it and ensure
88832 * that it represents a valid section of the address space.
88833 */
88834- addr = get_unmapped_area(file, addr, len, pgoff, flags);
88835+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
88836 if (addr & ~PAGE_MASK)
88837 return addr;
88838
88839@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88840 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
88841 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
88842
88843+#ifdef CONFIG_PAX_MPROTECT
88844+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88845+
88846+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
88847+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
88848+ mm->binfmt->handle_mmap)
88849+ mm->binfmt->handle_mmap(file);
88850+#endif
88851+
88852+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88853+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
88854+ gr_log_rwxmmap(file);
88855+
88856+#ifdef CONFIG_PAX_EMUPLT
88857+ vm_flags &= ~VM_EXEC;
88858+#else
88859+ return -EPERM;
88860+#endif
88861+
88862+ }
88863+
88864+ if (!(vm_flags & VM_EXEC))
88865+ vm_flags &= ~VM_MAYEXEC;
88866+#else
88867+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88868+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88869+#endif
88870+ else
88871+ vm_flags &= ~VM_MAYWRITE;
88872+ }
88873+#endif
88874+
88875+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88876+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
88877+ vm_flags &= ~VM_PAGEEXEC;
88878+#endif
88879+
88880 if (flags & MAP_LOCKED)
88881 if (!can_do_mlock())
88882 return -EPERM;
88883@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88884 locked += mm->locked_vm;
88885 lock_limit = rlimit(RLIMIT_MEMLOCK);
88886 lock_limit >>= PAGE_SHIFT;
88887+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
88888 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
88889 return -EAGAIN;
88890 }
88891@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88892 vm_flags |= VM_NORESERVE;
88893 }
88894
88895+ if (!gr_acl_handle_mmap(file, prot))
88896+ return -EACCES;
88897+
88898 addr = mmap_region(file, addr, len, vm_flags, pgoff);
88899 if (!IS_ERR_VALUE(addr) &&
88900 ((vm_flags & VM_LOCKED) ||
88901@@ -1432,7 +1556,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
88902 vm_flags_t vm_flags = vma->vm_flags;
88903
88904 /* If it was private or non-writable, the write bit is already clear */
88905- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
88906+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
88907 return 0;
88908
88909 /* The backer wishes to know when pages are first written to? */
88910@@ -1480,7 +1604,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88911 unsigned long charged = 0;
88912 struct inode *inode = file ? file_inode(file) : NULL;
88913
88914+#ifdef CONFIG_PAX_SEGMEXEC
88915+ struct vm_area_struct *vma_m = NULL;
88916+#endif
88917+
88918+ /*
88919+ * mm->mmap_sem is required to protect against another thread
88920+ * changing the mappings in case we sleep.
88921+ */
88922+ verify_mm_writelocked(mm);
88923+
88924 /* Check against address space limit. */
88925+
88926+#ifdef CONFIG_PAX_RANDMMAP
88927+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88928+#endif
88929+
88930 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
88931 unsigned long nr_pages;
88932
88933@@ -1499,11 +1638,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88934
88935 /* Clear old maps */
88936 error = -ENOMEM;
88937-munmap_back:
88938 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88939 if (do_munmap(mm, addr, len))
88940 return -ENOMEM;
88941- goto munmap_back;
88942+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88943 }
88944
88945 /*
88946@@ -1534,6 +1672,16 @@ munmap_back:
88947 goto unacct_error;
88948 }
88949
88950+#ifdef CONFIG_PAX_SEGMEXEC
88951+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
88952+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88953+ if (!vma_m) {
88954+ error = -ENOMEM;
88955+ goto free_vma;
88956+ }
88957+ }
88958+#endif
88959+
88960 vma->vm_mm = mm;
88961 vma->vm_start = addr;
88962 vma->vm_end = addr + len;
88963@@ -1558,6 +1706,13 @@ munmap_back:
88964 if (error)
88965 goto unmap_and_free_vma;
88966
88967+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88968+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
88969+ vma->vm_flags |= VM_PAGEEXEC;
88970+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88971+ }
88972+#endif
88973+
88974 /* Can addr have changed??
88975 *
88976 * Answer: Yes, several device drivers can do it in their
88977@@ -1596,6 +1751,11 @@ munmap_back:
88978 vma_link(mm, vma, prev, rb_link, rb_parent);
88979 file = vma->vm_file;
88980
88981+#ifdef CONFIG_PAX_SEGMEXEC
88982+ if (vma_m)
88983+ BUG_ON(pax_mirror_vma(vma_m, vma));
88984+#endif
88985+
88986 /* Once vma denies write, undo our temporary denial count */
88987 if (correct_wcount)
88988 atomic_inc(&inode->i_writecount);
88989@@ -1603,6 +1763,7 @@ out:
88990 perf_event_mmap(vma);
88991
88992 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
88993+ track_exec_limit(mm, addr, addr + len, vm_flags);
88994 if (vm_flags & VM_LOCKED) {
88995 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
88996 vma == get_gate_vma(current->mm)))
88997@@ -1626,6 +1787,12 @@ unmap_and_free_vma:
88998 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
88999 charged = 0;
89000 free_vma:
89001+
89002+#ifdef CONFIG_PAX_SEGMEXEC
89003+ if (vma_m)
89004+ kmem_cache_free(vm_area_cachep, vma_m);
89005+#endif
89006+
89007 kmem_cache_free(vm_area_cachep, vma);
89008 unacct_error:
89009 if (charged)
89010@@ -1633,7 +1800,63 @@ unacct_error:
89011 return error;
89012 }
89013
89014-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89015+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
89016+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
89017+{
89018+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
89019+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
89020+
89021+ return 0;
89022+}
89023+#endif
89024+
89025+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
89026+{
89027+ if (!vma) {
89028+#ifdef CONFIG_STACK_GROWSUP
89029+ if (addr > sysctl_heap_stack_gap)
89030+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
89031+ else
89032+ vma = find_vma(current->mm, 0);
89033+ if (vma && (vma->vm_flags & VM_GROWSUP))
89034+ return false;
89035+#endif
89036+ return true;
89037+ }
89038+
89039+ if (addr + len > vma->vm_start)
89040+ return false;
89041+
89042+ if (vma->vm_flags & VM_GROWSDOWN)
89043+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
89044+#ifdef CONFIG_STACK_GROWSUP
89045+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
89046+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
89047+#endif
89048+ else if (offset)
89049+ return offset <= vma->vm_start - addr - len;
89050+
89051+ return true;
89052+}
89053+
89054+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
89055+{
89056+ if (vma->vm_start < len)
89057+ return -ENOMEM;
89058+
89059+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
89060+ if (offset <= vma->vm_start - len)
89061+ return vma->vm_start - len - offset;
89062+ else
89063+ return -ENOMEM;
89064+ }
89065+
89066+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
89067+ return vma->vm_start - len - sysctl_heap_stack_gap;
89068+ return -ENOMEM;
89069+}
89070+
89071+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
89072 {
89073 /*
89074 * We implement the search by looking for an rbtree node that
89075@@ -1681,11 +1904,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
89076 }
89077 }
89078
89079- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
89080+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
89081 check_current:
89082 /* Check if current node has a suitable gap */
89083 if (gap_start > high_limit)
89084 return -ENOMEM;
89085+
89086+ if (gap_end - gap_start > info->threadstack_offset)
89087+ gap_start += info->threadstack_offset;
89088+ else
89089+ gap_start = gap_end;
89090+
89091+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
89092+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89093+ gap_start += sysctl_heap_stack_gap;
89094+ else
89095+ gap_start = gap_end;
89096+ }
89097+ if (vma->vm_flags & VM_GROWSDOWN) {
89098+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89099+ gap_end -= sysctl_heap_stack_gap;
89100+ else
89101+ gap_end = gap_start;
89102+ }
89103 if (gap_end >= low_limit && gap_end - gap_start >= length)
89104 goto found;
89105
89106@@ -1735,7 +1976,7 @@ found:
89107 return gap_start;
89108 }
89109
89110-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
89111+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
89112 {
89113 struct mm_struct *mm = current->mm;
89114 struct vm_area_struct *vma;
89115@@ -1789,6 +2030,24 @@ check_current:
89116 gap_end = vma->vm_start;
89117 if (gap_end < low_limit)
89118 return -ENOMEM;
89119+
89120+ if (gap_end - gap_start > info->threadstack_offset)
89121+ gap_end -= info->threadstack_offset;
89122+ else
89123+ gap_end = gap_start;
89124+
89125+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
89126+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89127+ gap_start += sysctl_heap_stack_gap;
89128+ else
89129+ gap_start = gap_end;
89130+ }
89131+ if (vma->vm_flags & VM_GROWSDOWN) {
89132+ if (gap_end - gap_start > sysctl_heap_stack_gap)
89133+ gap_end -= sysctl_heap_stack_gap;
89134+ else
89135+ gap_end = gap_start;
89136+ }
89137 if (gap_start <= high_limit && gap_end - gap_start >= length)
89138 goto found;
89139
89140@@ -1852,6 +2111,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
89141 struct mm_struct *mm = current->mm;
89142 struct vm_area_struct *vma;
89143 struct vm_unmapped_area_info info;
89144+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
89145
89146 if (len > TASK_SIZE)
89147 return -ENOMEM;
89148@@ -1859,29 +2119,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
89149 if (flags & MAP_FIXED)
89150 return addr;
89151
89152+#ifdef CONFIG_PAX_RANDMMAP
89153+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
89154+#endif
89155+
89156 if (addr) {
89157 addr = PAGE_ALIGN(addr);
89158 vma = find_vma(mm, addr);
89159- if (TASK_SIZE - len >= addr &&
89160- (!vma || addr + len <= vma->vm_start))
89161+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
89162 return addr;
89163 }
89164
89165 info.flags = 0;
89166 info.length = len;
89167 info.low_limit = TASK_UNMAPPED_BASE;
89168+
89169+#ifdef CONFIG_PAX_RANDMMAP
89170+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89171+ info.low_limit += mm->delta_mmap;
89172+#endif
89173+
89174 info.high_limit = TASK_SIZE;
89175 info.align_mask = 0;
89176+ info.threadstack_offset = offset;
89177 return vm_unmapped_area(&info);
89178 }
89179 #endif
89180
89181 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
89182 {
89183+
89184+#ifdef CONFIG_PAX_SEGMEXEC
89185+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
89186+ return;
89187+#endif
89188+
89189 /*
89190 * Is this a new hole at the lowest possible address?
89191 */
89192- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
89193+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
89194 mm->free_area_cache = addr;
89195 }
89196
89197@@ -1899,6 +2175,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89198 struct mm_struct *mm = current->mm;
89199 unsigned long addr = addr0;
89200 struct vm_unmapped_area_info info;
89201+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
89202
89203 /* requested length too big for entire address space */
89204 if (len > TASK_SIZE)
89205@@ -1907,12 +2184,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89206 if (flags & MAP_FIXED)
89207 return addr;
89208
89209+#ifdef CONFIG_PAX_RANDMMAP
89210+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
89211+#endif
89212+
89213 /* requesting a specific address */
89214 if (addr) {
89215 addr = PAGE_ALIGN(addr);
89216 vma = find_vma(mm, addr);
89217- if (TASK_SIZE - len >= addr &&
89218- (!vma || addr + len <= vma->vm_start))
89219+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
89220 return addr;
89221 }
89222
89223@@ -1921,6 +2201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89224 info.low_limit = PAGE_SIZE;
89225 info.high_limit = mm->mmap_base;
89226 info.align_mask = 0;
89227+ info.threadstack_offset = offset;
89228 addr = vm_unmapped_area(&info);
89229
89230 /*
89231@@ -1933,6 +2214,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89232 VM_BUG_ON(addr != -ENOMEM);
89233 info.flags = 0;
89234 info.low_limit = TASK_UNMAPPED_BASE;
89235+
89236+#ifdef CONFIG_PAX_RANDMMAP
89237+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89238+ info.low_limit += mm->delta_mmap;
89239+#endif
89240+
89241 info.high_limit = TASK_SIZE;
89242 addr = vm_unmapped_area(&info);
89243 }
89244@@ -1943,6 +2230,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
89245
89246 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
89247 {
89248+
89249+#ifdef CONFIG_PAX_SEGMEXEC
89250+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
89251+ return;
89252+#endif
89253+
89254 /*
89255 * Is this a new hole at the highest possible address?
89256 */
89257@@ -1950,8 +2243,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
89258 mm->free_area_cache = addr;
89259
89260 /* dont allow allocations above current base */
89261- if (mm->free_area_cache > mm->mmap_base)
89262+ if (mm->free_area_cache > mm->mmap_base) {
89263 mm->free_area_cache = mm->mmap_base;
89264+ mm->cached_hole_size = ~0UL;
89265+ }
89266 }
89267
89268 unsigned long
89269@@ -2047,6 +2342,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
89270 return vma;
89271 }
89272
89273+#ifdef CONFIG_PAX_SEGMEXEC
89274+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
89275+{
89276+ struct vm_area_struct *vma_m;
89277+
89278+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
89279+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
89280+ BUG_ON(vma->vm_mirror);
89281+ return NULL;
89282+ }
89283+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
89284+ vma_m = vma->vm_mirror;
89285+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
89286+ BUG_ON(vma->vm_file != vma_m->vm_file);
89287+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
89288+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
89289+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
89290+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
89291+ return vma_m;
89292+}
89293+#endif
89294+
89295 /*
89296 * Verify that the stack growth is acceptable and
89297 * update accounting. This is shared with both the
89298@@ -2063,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89299 return -ENOMEM;
89300
89301 /* Stack limit test */
89302+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
89303 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
89304 return -ENOMEM;
89305
89306@@ -2073,6 +2391,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89307 locked = mm->locked_vm + grow;
89308 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
89309 limit >>= PAGE_SHIFT;
89310+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
89311 if (locked > limit && !capable(CAP_IPC_LOCK))
89312 return -ENOMEM;
89313 }
89314@@ -2102,37 +2421,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89315 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
89316 * vma is the last one with address > vma->vm_end. Have to extend vma.
89317 */
89318+#ifndef CONFIG_IA64
89319+static
89320+#endif
89321 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89322 {
89323 int error;
89324+ bool locknext;
89325
89326 if (!(vma->vm_flags & VM_GROWSUP))
89327 return -EFAULT;
89328
89329+ /* Also guard against wrapping around to address 0. */
89330+ if (address < PAGE_ALIGN(address+1))
89331+ address = PAGE_ALIGN(address+1);
89332+ else
89333+ return -ENOMEM;
89334+
89335 /*
89336 * We must make sure the anon_vma is allocated
89337 * so that the anon_vma locking is not a noop.
89338 */
89339 if (unlikely(anon_vma_prepare(vma)))
89340 return -ENOMEM;
89341+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
89342+ if (locknext && anon_vma_prepare(vma->vm_next))
89343+ return -ENOMEM;
89344 vma_lock_anon_vma(vma);
89345+ if (locknext)
89346+ vma_lock_anon_vma(vma->vm_next);
89347
89348 /*
89349 * vma->vm_start/vm_end cannot change under us because the caller
89350 * is required to hold the mmap_sem in read mode. We need the
89351- * anon_vma lock to serialize against concurrent expand_stacks.
89352- * Also guard against wrapping around to address 0.
89353+ * anon_vma locks to serialize against concurrent expand_stacks
89354+ * and expand_upwards.
89355 */
89356- if (address < PAGE_ALIGN(address+4))
89357- address = PAGE_ALIGN(address+4);
89358- else {
89359- vma_unlock_anon_vma(vma);
89360- return -ENOMEM;
89361- }
89362 error = 0;
89363
89364 /* Somebody else might have raced and expanded it already */
89365- if (address > vma->vm_end) {
89366+ 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)
89367+ error = -ENOMEM;
89368+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
89369 unsigned long size, grow;
89370
89371 size = address - vma->vm_start;
89372@@ -2167,6 +2497,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89373 }
89374 }
89375 }
89376+ if (locknext)
89377+ vma_unlock_anon_vma(vma->vm_next);
89378 vma_unlock_anon_vma(vma);
89379 khugepaged_enter_vma_merge(vma);
89380 validate_mm(vma->vm_mm);
89381@@ -2181,6 +2513,8 @@ int expand_downwards(struct vm_area_struct *vma,
89382 unsigned long address)
89383 {
89384 int error;
89385+ bool lockprev = false;
89386+ struct vm_area_struct *prev;
89387
89388 /*
89389 * We must make sure the anon_vma is allocated
89390@@ -2194,6 +2528,15 @@ int expand_downwards(struct vm_area_struct *vma,
89391 if (error)
89392 return error;
89393
89394+ prev = vma->vm_prev;
89395+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
89396+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
89397+#endif
89398+ if (lockprev && anon_vma_prepare(prev))
89399+ return -ENOMEM;
89400+ if (lockprev)
89401+ vma_lock_anon_vma(prev);
89402+
89403 vma_lock_anon_vma(vma);
89404
89405 /*
89406@@ -2203,9 +2546,17 @@ int expand_downwards(struct vm_area_struct *vma,
89407 */
89408
89409 /* Somebody else might have raced and expanded it already */
89410- if (address < vma->vm_start) {
89411+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
89412+ error = -ENOMEM;
89413+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
89414 unsigned long size, grow;
89415
89416+#ifdef CONFIG_PAX_SEGMEXEC
89417+ struct vm_area_struct *vma_m;
89418+
89419+ vma_m = pax_find_mirror_vma(vma);
89420+#endif
89421+
89422 size = vma->vm_end - address;
89423 grow = (vma->vm_start - address) >> PAGE_SHIFT;
89424
89425@@ -2230,13 +2581,27 @@ int expand_downwards(struct vm_area_struct *vma,
89426 vma->vm_pgoff -= grow;
89427 anon_vma_interval_tree_post_update_vma(vma);
89428 vma_gap_update(vma);
89429+
89430+#ifdef CONFIG_PAX_SEGMEXEC
89431+ if (vma_m) {
89432+ anon_vma_interval_tree_pre_update_vma(vma_m);
89433+ vma_m->vm_start -= grow << PAGE_SHIFT;
89434+ vma_m->vm_pgoff -= grow;
89435+ anon_vma_interval_tree_post_update_vma(vma_m);
89436+ vma_gap_update(vma_m);
89437+ }
89438+#endif
89439+
89440 spin_unlock(&vma->vm_mm->page_table_lock);
89441
89442+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
89443 perf_event_mmap(vma);
89444 }
89445 }
89446 }
89447 vma_unlock_anon_vma(vma);
89448+ if (lockprev)
89449+ vma_unlock_anon_vma(prev);
89450 khugepaged_enter_vma_merge(vma);
89451 validate_mm(vma->vm_mm);
89452 return error;
89453@@ -2334,6 +2699,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
89454 do {
89455 long nrpages = vma_pages(vma);
89456
89457+#ifdef CONFIG_PAX_SEGMEXEC
89458+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
89459+ vma = remove_vma(vma);
89460+ continue;
89461+ }
89462+#endif
89463+
89464 if (vma->vm_flags & VM_ACCOUNT)
89465 nr_accounted += nrpages;
89466 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
89467@@ -2379,6 +2751,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
89468 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
89469 vma->vm_prev = NULL;
89470 do {
89471+
89472+#ifdef CONFIG_PAX_SEGMEXEC
89473+ if (vma->vm_mirror) {
89474+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
89475+ vma->vm_mirror->vm_mirror = NULL;
89476+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
89477+ vma->vm_mirror = NULL;
89478+ }
89479+#endif
89480+
89481 vma_rb_erase(vma, &mm->mm_rb);
89482 mm->map_count--;
89483 tail_vma = vma;
89484@@ -2410,14 +2792,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89485 struct vm_area_struct *new;
89486 int err = -ENOMEM;
89487
89488+#ifdef CONFIG_PAX_SEGMEXEC
89489+ struct vm_area_struct *vma_m, *new_m = NULL;
89490+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
89491+#endif
89492+
89493 if (is_vm_hugetlb_page(vma) && (addr &
89494 ~(huge_page_mask(hstate_vma(vma)))))
89495 return -EINVAL;
89496
89497+#ifdef CONFIG_PAX_SEGMEXEC
89498+ vma_m = pax_find_mirror_vma(vma);
89499+#endif
89500+
89501 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89502 if (!new)
89503 goto out_err;
89504
89505+#ifdef CONFIG_PAX_SEGMEXEC
89506+ if (vma_m) {
89507+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89508+ if (!new_m) {
89509+ kmem_cache_free(vm_area_cachep, new);
89510+ goto out_err;
89511+ }
89512+ }
89513+#endif
89514+
89515 /* most fields are the same, copy all, and then fixup */
89516 *new = *vma;
89517
89518@@ -2430,6 +2831,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89519 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
89520 }
89521
89522+#ifdef CONFIG_PAX_SEGMEXEC
89523+ if (vma_m) {
89524+ *new_m = *vma_m;
89525+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
89526+ new_m->vm_mirror = new;
89527+ new->vm_mirror = new_m;
89528+
89529+ if (new_below)
89530+ new_m->vm_end = addr_m;
89531+ else {
89532+ new_m->vm_start = addr_m;
89533+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
89534+ }
89535+ }
89536+#endif
89537+
89538 pol = mpol_dup(vma_policy(vma));
89539 if (IS_ERR(pol)) {
89540 err = PTR_ERR(pol);
89541@@ -2452,6 +2869,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89542 else
89543 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
89544
89545+#ifdef CONFIG_PAX_SEGMEXEC
89546+ if (!err && vma_m) {
89547+ if (anon_vma_clone(new_m, vma_m))
89548+ goto out_free_mpol;
89549+
89550+ mpol_get(pol);
89551+ vma_set_policy(new_m, pol);
89552+
89553+ if (new_m->vm_file)
89554+ get_file(new_m->vm_file);
89555+
89556+ if (new_m->vm_ops && new_m->vm_ops->open)
89557+ new_m->vm_ops->open(new_m);
89558+
89559+ if (new_below)
89560+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
89561+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
89562+ else
89563+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
89564+
89565+ if (err) {
89566+ if (new_m->vm_ops && new_m->vm_ops->close)
89567+ new_m->vm_ops->close(new_m);
89568+ if (new_m->vm_file)
89569+ fput(new_m->vm_file);
89570+ mpol_put(pol);
89571+ }
89572+ }
89573+#endif
89574+
89575 /* Success. */
89576 if (!err)
89577 return 0;
89578@@ -2461,10 +2908,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89579 new->vm_ops->close(new);
89580 if (new->vm_file)
89581 fput(new->vm_file);
89582- unlink_anon_vmas(new);
89583 out_free_mpol:
89584 mpol_put(pol);
89585 out_free_vma:
89586+
89587+#ifdef CONFIG_PAX_SEGMEXEC
89588+ if (new_m) {
89589+ unlink_anon_vmas(new_m);
89590+ kmem_cache_free(vm_area_cachep, new_m);
89591+ }
89592+#endif
89593+
89594+ unlink_anon_vmas(new);
89595 kmem_cache_free(vm_area_cachep, new);
89596 out_err:
89597 return err;
89598@@ -2477,6 +2932,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89599 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89600 unsigned long addr, int new_below)
89601 {
89602+
89603+#ifdef CONFIG_PAX_SEGMEXEC
89604+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
89605+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
89606+ if (mm->map_count >= sysctl_max_map_count-1)
89607+ return -ENOMEM;
89608+ } else
89609+#endif
89610+
89611 if (mm->map_count >= sysctl_max_map_count)
89612 return -ENOMEM;
89613
89614@@ -2488,11 +2952,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89615 * work. This now handles partial unmappings.
89616 * Jeremy Fitzhardinge <jeremy@goop.org>
89617 */
89618+#ifdef CONFIG_PAX_SEGMEXEC
89619 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89620 {
89621+ int ret = __do_munmap(mm, start, len);
89622+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
89623+ return ret;
89624+
89625+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
89626+}
89627+
89628+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89629+#else
89630+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89631+#endif
89632+{
89633 unsigned long end;
89634 struct vm_area_struct *vma, *prev, *last;
89635
89636+ /*
89637+ * mm->mmap_sem is required to protect against another thread
89638+ * changing the mappings in case we sleep.
89639+ */
89640+ verify_mm_writelocked(mm);
89641+
89642 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
89643 return -EINVAL;
89644
89645@@ -2567,6 +3050,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89646 /* Fix up all other VM information */
89647 remove_vma_list(mm, vma);
89648
89649+ track_exec_limit(mm, start, end, 0UL);
89650+
89651 return 0;
89652 }
89653
89654@@ -2575,6 +3060,13 @@ int vm_munmap(unsigned long start, size_t len)
89655 int ret;
89656 struct mm_struct *mm = current->mm;
89657
89658+
89659+#ifdef CONFIG_PAX_SEGMEXEC
89660+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
89661+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
89662+ return -EINVAL;
89663+#endif
89664+
89665 down_write(&mm->mmap_sem);
89666 ret = do_munmap(mm, start, len);
89667 up_write(&mm->mmap_sem);
89668@@ -2588,16 +3080,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
89669 return vm_munmap(addr, len);
89670 }
89671
89672-static inline void verify_mm_writelocked(struct mm_struct *mm)
89673-{
89674-#ifdef CONFIG_DEBUG_VM
89675- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
89676- WARN_ON(1);
89677- up_read(&mm->mmap_sem);
89678- }
89679-#endif
89680-}
89681-
89682 /*
89683 * this is really a simplified "do_mmap". it only handles
89684 * anonymous maps. eventually we may be able to do some
89685@@ -2611,6 +3093,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89686 struct rb_node ** rb_link, * rb_parent;
89687 pgoff_t pgoff = addr >> PAGE_SHIFT;
89688 int error;
89689+ unsigned long charged;
89690
89691 len = PAGE_ALIGN(len);
89692 if (!len)
89693@@ -2618,16 +3101,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89694
89695 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
89696
89697+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
89698+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
89699+ flags &= ~VM_EXEC;
89700+
89701+#ifdef CONFIG_PAX_MPROTECT
89702+ if (mm->pax_flags & MF_PAX_MPROTECT)
89703+ flags &= ~VM_MAYEXEC;
89704+#endif
89705+
89706+ }
89707+#endif
89708+
89709 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
89710 if (error & ~PAGE_MASK)
89711 return error;
89712
89713+ charged = len >> PAGE_SHIFT;
89714+
89715 /*
89716 * mlock MCL_FUTURE?
89717 */
89718 if (mm->def_flags & VM_LOCKED) {
89719 unsigned long locked, lock_limit;
89720- locked = len >> PAGE_SHIFT;
89721+ locked = charged;
89722 locked += mm->locked_vm;
89723 lock_limit = rlimit(RLIMIT_MEMLOCK);
89724 lock_limit >>= PAGE_SHIFT;
89725@@ -2644,21 +3141,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89726 /*
89727 * Clear old maps. this also does some error checking for us
89728 */
89729- munmap_back:
89730 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
89731 if (do_munmap(mm, addr, len))
89732 return -ENOMEM;
89733- goto munmap_back;
89734+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
89735 }
89736
89737 /* Check against address space limits *after* clearing old maps... */
89738- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
89739+ if (!may_expand_vm(mm, charged))
89740 return -ENOMEM;
89741
89742 if (mm->map_count > sysctl_max_map_count)
89743 return -ENOMEM;
89744
89745- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
89746+ if (security_vm_enough_memory_mm(mm, charged))
89747 return -ENOMEM;
89748
89749 /* Can we just expand an old private anonymous mapping? */
89750@@ -2672,7 +3168,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89751 */
89752 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89753 if (!vma) {
89754- vm_unacct_memory(len >> PAGE_SHIFT);
89755+ vm_unacct_memory(charged);
89756 return -ENOMEM;
89757 }
89758
89759@@ -2686,9 +3182,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89760 vma_link(mm, vma, prev, rb_link, rb_parent);
89761 out:
89762 perf_event_mmap(vma);
89763- mm->total_vm += len >> PAGE_SHIFT;
89764+ mm->total_vm += charged;
89765 if (flags & VM_LOCKED)
89766- mm->locked_vm += (len >> PAGE_SHIFT);
89767+ mm->locked_vm += charged;
89768+ track_exec_limit(mm, addr, addr + len, flags);
89769 return addr;
89770 }
89771
89772@@ -2750,6 +3247,7 @@ void exit_mmap(struct mm_struct *mm)
89773 while (vma) {
89774 if (vma->vm_flags & VM_ACCOUNT)
89775 nr_accounted += vma_pages(vma);
89776+ vma->vm_mirror = NULL;
89777 vma = remove_vma(vma);
89778 }
89779 vm_unacct_memory(nr_accounted);
89780@@ -2766,6 +3264,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89781 struct vm_area_struct *prev;
89782 struct rb_node **rb_link, *rb_parent;
89783
89784+#ifdef CONFIG_PAX_SEGMEXEC
89785+ struct vm_area_struct *vma_m = NULL;
89786+#endif
89787+
89788+ if (security_mmap_addr(vma->vm_start))
89789+ return -EPERM;
89790+
89791 /*
89792 * The vm_pgoff of a purely anonymous vma should be irrelevant
89793 * until its first write fault, when page's anon_vma and index
89794@@ -2789,7 +3294,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89795 security_vm_enough_memory_mm(mm, vma_pages(vma)))
89796 return -ENOMEM;
89797
89798+#ifdef CONFIG_PAX_SEGMEXEC
89799+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
89800+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89801+ if (!vma_m)
89802+ return -ENOMEM;
89803+ }
89804+#endif
89805+
89806 vma_link(mm, vma, prev, rb_link, rb_parent);
89807+
89808+#ifdef CONFIG_PAX_SEGMEXEC
89809+ if (vma_m)
89810+ BUG_ON(pax_mirror_vma(vma_m, vma));
89811+#endif
89812+
89813 return 0;
89814 }
89815
89816@@ -2809,6 +3328,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89817 struct mempolicy *pol;
89818 bool faulted_in_anon_vma = true;
89819
89820+ BUG_ON(vma->vm_mirror);
89821+
89822 /*
89823 * If anonymous vma has not yet been faulted, update new pgoff
89824 * to match new location, to increase its chance of merging.
89825@@ -2875,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89826 return NULL;
89827 }
89828
89829+#ifdef CONFIG_PAX_SEGMEXEC
89830+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
89831+{
89832+ struct vm_area_struct *prev_m;
89833+ struct rb_node **rb_link_m, *rb_parent_m;
89834+ struct mempolicy *pol_m;
89835+
89836+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
89837+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
89838+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
89839+ *vma_m = *vma;
89840+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
89841+ if (anon_vma_clone(vma_m, vma))
89842+ return -ENOMEM;
89843+ pol_m = vma_policy(vma_m);
89844+ mpol_get(pol_m);
89845+ vma_set_policy(vma_m, pol_m);
89846+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
89847+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
89848+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
89849+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
89850+ if (vma_m->vm_file)
89851+ get_file(vma_m->vm_file);
89852+ if (vma_m->vm_ops && vma_m->vm_ops->open)
89853+ vma_m->vm_ops->open(vma_m);
89854+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
89855+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
89856+ vma_m->vm_mirror = vma;
89857+ vma->vm_mirror = vma_m;
89858+ return 0;
89859+}
89860+#endif
89861+
89862 /*
89863 * Return true if the calling process may expand its vm space by the passed
89864 * number of pages
89865@@ -2886,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
89866
89867 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
89868
89869+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
89870 if (cur + npages > lim)
89871 return 0;
89872 return 1;
89873@@ -2956,6 +3511,22 @@ int install_special_mapping(struct mm_struct *mm,
89874 vma->vm_start = addr;
89875 vma->vm_end = addr + len;
89876
89877+#ifdef CONFIG_PAX_MPROTECT
89878+ if (mm->pax_flags & MF_PAX_MPROTECT) {
89879+#ifndef CONFIG_PAX_MPROTECT_COMPAT
89880+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
89881+ return -EPERM;
89882+ if (!(vm_flags & VM_EXEC))
89883+ vm_flags &= ~VM_MAYEXEC;
89884+#else
89885+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
89886+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
89887+#endif
89888+ else
89889+ vm_flags &= ~VM_MAYWRITE;
89890+ }
89891+#endif
89892+
89893 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
89894 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
89895
89896diff --git a/mm/mprotect.c b/mm/mprotect.c
89897index 94722a4..e661e29 100644
89898--- a/mm/mprotect.c
89899+++ b/mm/mprotect.c
89900@@ -23,10 +23,18 @@
89901 #include <linux/mmu_notifier.h>
89902 #include <linux/migrate.h>
89903 #include <linux/perf_event.h>
89904+#include <linux/sched/sysctl.h>
89905+
89906+#ifdef CONFIG_PAX_MPROTECT
89907+#include <linux/elf.h>
89908+#include <linux/binfmts.h>
89909+#endif
89910+
89911 #include <asm/uaccess.h>
89912 #include <asm/pgtable.h>
89913 #include <asm/cacheflush.h>
89914 #include <asm/tlbflush.h>
89915+#include <asm/mmu_context.h>
89916
89917 #ifndef pgprot_modify
89918 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
89919@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
89920 return pages;
89921 }
89922
89923+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
89924+/* called while holding the mmap semaphor for writing except stack expansion */
89925+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
89926+{
89927+ unsigned long oldlimit, newlimit = 0UL;
89928+
89929+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
89930+ return;
89931+
89932+ spin_lock(&mm->page_table_lock);
89933+ oldlimit = mm->context.user_cs_limit;
89934+ if ((prot & VM_EXEC) && oldlimit < end)
89935+ /* USER_CS limit moved up */
89936+ newlimit = end;
89937+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
89938+ /* USER_CS limit moved down */
89939+ newlimit = start;
89940+
89941+ if (newlimit) {
89942+ mm->context.user_cs_limit = newlimit;
89943+
89944+#ifdef CONFIG_SMP
89945+ wmb();
89946+ cpus_clear(mm->context.cpu_user_cs_mask);
89947+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
89948+#endif
89949+
89950+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
89951+ }
89952+ spin_unlock(&mm->page_table_lock);
89953+ if (newlimit == end) {
89954+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
89955+
89956+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
89957+ if (is_vm_hugetlb_page(vma))
89958+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
89959+ else
89960+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
89961+ }
89962+}
89963+#endif
89964+
89965 int
89966 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89967 unsigned long start, unsigned long end, unsigned long newflags)
89968@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89969 int error;
89970 int dirty_accountable = 0;
89971
89972+#ifdef CONFIG_PAX_SEGMEXEC
89973+ struct vm_area_struct *vma_m = NULL;
89974+ unsigned long start_m, end_m;
89975+
89976+ start_m = start + SEGMEXEC_TASK_SIZE;
89977+ end_m = end + SEGMEXEC_TASK_SIZE;
89978+#endif
89979+
89980 if (newflags == oldflags) {
89981 *pprev = vma;
89982 return 0;
89983 }
89984
89985+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
89986+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
89987+
89988+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
89989+ return -ENOMEM;
89990+
89991+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
89992+ return -ENOMEM;
89993+ }
89994+
89995 /*
89996 * If we make a private mapping writable we increase our commit;
89997 * but (without finer accounting) cannot reduce our commit if we
89998@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89999 }
90000 }
90001
90002+#ifdef CONFIG_PAX_SEGMEXEC
90003+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
90004+ if (start != vma->vm_start) {
90005+ error = split_vma(mm, vma, start, 1);
90006+ if (error)
90007+ goto fail;
90008+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
90009+ *pprev = (*pprev)->vm_next;
90010+ }
90011+
90012+ if (end != vma->vm_end) {
90013+ error = split_vma(mm, vma, end, 0);
90014+ if (error)
90015+ goto fail;
90016+ }
90017+
90018+ if (pax_find_mirror_vma(vma)) {
90019+ error = __do_munmap(mm, start_m, end_m - start_m);
90020+ if (error)
90021+ goto fail;
90022+ } else {
90023+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
90024+ if (!vma_m) {
90025+ error = -ENOMEM;
90026+ goto fail;
90027+ }
90028+ vma->vm_flags = newflags;
90029+ error = pax_mirror_vma(vma_m, vma);
90030+ if (error) {
90031+ vma->vm_flags = oldflags;
90032+ goto fail;
90033+ }
90034+ }
90035+ }
90036+#endif
90037+
90038 /*
90039 * First try to merge with previous and/or next vma.
90040 */
90041@@ -296,9 +400,21 @@ success:
90042 * vm_flags and vm_page_prot are protected by the mmap_sem
90043 * held in write mode.
90044 */
90045+
90046+#ifdef CONFIG_PAX_SEGMEXEC
90047+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
90048+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
90049+#endif
90050+
90051 vma->vm_flags = newflags;
90052+
90053+#ifdef CONFIG_PAX_MPROTECT
90054+ if (mm->binfmt && mm->binfmt->handle_mprotect)
90055+ mm->binfmt->handle_mprotect(vma, newflags);
90056+#endif
90057+
90058 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
90059- vm_get_page_prot(newflags));
90060+ vm_get_page_prot(vma->vm_flags));
90061
90062 if (vma_wants_writenotify(vma)) {
90063 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
90064@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90065 end = start + len;
90066 if (end <= start)
90067 return -ENOMEM;
90068+
90069+#ifdef CONFIG_PAX_SEGMEXEC
90070+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90071+ if (end > SEGMEXEC_TASK_SIZE)
90072+ return -EINVAL;
90073+ } else
90074+#endif
90075+
90076+ if (end > TASK_SIZE)
90077+ return -EINVAL;
90078+
90079 if (!arch_validate_prot(prot))
90080 return -EINVAL;
90081
90082@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90083 /*
90084 * Does the application expect PROT_READ to imply PROT_EXEC:
90085 */
90086- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
90087+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
90088 prot |= PROT_EXEC;
90089
90090 vm_flags = calc_vm_prot_bits(prot);
90091@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90092 if (start > vma->vm_start)
90093 prev = vma;
90094
90095+#ifdef CONFIG_PAX_MPROTECT
90096+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
90097+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
90098+#endif
90099+
90100 for (nstart = start ; ; ) {
90101 unsigned long newflags;
90102
90103@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90104
90105 /* newflags >> 4 shift VM_MAY% in place of VM_% */
90106 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
90107+ if (prot & (PROT_WRITE | PROT_EXEC))
90108+ gr_log_rwxmprotect(vma);
90109+
90110+ error = -EACCES;
90111+ goto out;
90112+ }
90113+
90114+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
90115 error = -EACCES;
90116 goto out;
90117 }
90118@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
90119 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
90120 if (error)
90121 goto out;
90122+
90123+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
90124+
90125 nstart = tmp;
90126
90127 if (nstart < prev->vm_end)
90128diff --git a/mm/mremap.c b/mm/mremap.c
90129index 463a257..c0c7a92 100644
90130--- a/mm/mremap.c
90131+++ b/mm/mremap.c
90132@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
90133 continue;
90134 pte = ptep_get_and_clear(mm, old_addr, old_pte);
90135 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
90136+
90137+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
90138+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
90139+ pte = pte_exprotect(pte);
90140+#endif
90141+
90142 set_pte_at(mm, new_addr, new_pte, pte);
90143 }
90144
90145@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
90146 if (is_vm_hugetlb_page(vma))
90147 goto Einval;
90148
90149+#ifdef CONFIG_PAX_SEGMEXEC
90150+ if (pax_find_mirror_vma(vma))
90151+ goto Einval;
90152+#endif
90153+
90154 /* We can't remap across vm area boundaries */
90155 if (old_len > vma->vm_end - addr)
90156 goto Efault;
90157@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
90158 unsigned long ret = -EINVAL;
90159 unsigned long charged = 0;
90160 unsigned long map_flags;
90161+ unsigned long pax_task_size = TASK_SIZE;
90162
90163 if (new_addr & ~PAGE_MASK)
90164 goto out;
90165
90166- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
90167+#ifdef CONFIG_PAX_SEGMEXEC
90168+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
90169+ pax_task_size = SEGMEXEC_TASK_SIZE;
90170+#endif
90171+
90172+ pax_task_size -= PAGE_SIZE;
90173+
90174+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
90175 goto out;
90176
90177 /* Check if the location we're moving into overlaps the
90178 * old location at all, and fail if it does.
90179 */
90180- if ((new_addr <= addr) && (new_addr+new_len) > addr)
90181- goto out;
90182-
90183- if ((addr <= new_addr) && (addr+old_len) > new_addr)
90184+ if (addr + old_len > new_addr && new_addr + new_len > addr)
90185 goto out;
90186
90187 ret = do_munmap(mm, new_addr, new_len);
90188@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90189 unsigned long ret = -EINVAL;
90190 unsigned long charged = 0;
90191 bool locked = false;
90192+ unsigned long pax_task_size = TASK_SIZE;
90193
90194 down_write(&current->mm->mmap_sem);
90195
90196@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90197 if (!new_len)
90198 goto out;
90199
90200+#ifdef CONFIG_PAX_SEGMEXEC
90201+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
90202+ pax_task_size = SEGMEXEC_TASK_SIZE;
90203+#endif
90204+
90205+ pax_task_size -= PAGE_SIZE;
90206+
90207+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
90208+ old_len > pax_task_size || addr > pax_task_size-old_len)
90209+ goto out;
90210+
90211 if (flags & MREMAP_FIXED) {
90212 if (flags & MREMAP_MAYMOVE)
90213 ret = mremap_to(addr, old_len, new_addr, new_len,
90214@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90215 new_addr = addr;
90216 }
90217 ret = addr;
90218+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
90219 goto out;
90220 }
90221 }
90222@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
90223 goto out;
90224 }
90225
90226+ map_flags = vma->vm_flags;
90227 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
90228+ if (!(ret & ~PAGE_MASK)) {
90229+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
90230+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
90231+ }
90232 }
90233 out:
90234 if (ret & ~PAGE_MASK)
90235diff --git a/mm/nommu.c b/mm/nommu.c
90236index 298884d..5f74980 100644
90237--- a/mm/nommu.c
90238+++ b/mm/nommu.c
90239@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
90240 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
90241 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
90242 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
90243-int heap_stack_gap = 0;
90244
90245 atomic_long_t mmap_pages_allocated;
90246
90247@@ -842,15 +841,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
90248 EXPORT_SYMBOL(find_vma);
90249
90250 /*
90251- * find a VMA
90252- * - we don't extend stack VMAs under NOMMU conditions
90253- */
90254-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
90255-{
90256- return find_vma(mm, addr);
90257-}
90258-
90259-/*
90260 * expand a stack to a given address
90261 * - not supported under NOMMU conditions
90262 */
90263@@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
90264
90265 /* most fields are the same, copy all, and then fixup */
90266 *new = *vma;
90267+ INIT_LIST_HEAD(&new->anon_vma_chain);
90268 *region = *vma->vm_region;
90269 new->vm_region = region;
90270
90271@@ -1995,8 +1986,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
90272 }
90273 EXPORT_SYMBOL(generic_file_remap_pages);
90274
90275-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90276- unsigned long addr, void *buf, int len, int write)
90277+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90278+ unsigned long addr, void *buf, size_t len, int write)
90279 {
90280 struct vm_area_struct *vma;
90281
90282@@ -2037,8 +2028,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
90283 *
90284 * The caller must hold a reference on @mm.
90285 */
90286-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90287- void *buf, int len, int write)
90288+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
90289+ void *buf, size_t len, int write)
90290 {
90291 return __access_remote_vm(NULL, mm, addr, buf, len, write);
90292 }
90293@@ -2047,7 +2038,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90294 * Access another process' address space.
90295 * - source/target buffer must be kernel space
90296 */
90297-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
90298+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
90299 {
90300 struct mm_struct *mm;
90301
90302diff --git a/mm/page-writeback.c b/mm/page-writeback.c
90303index 4514ad7..92eaa1c 100644
90304--- a/mm/page-writeback.c
90305+++ b/mm/page-writeback.c
90306@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
90307 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
90308 * - the bdi dirty thresh drops quickly due to change of JBOD workload
90309 */
90310-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
90311+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
90312 unsigned long thresh,
90313 unsigned long bg_thresh,
90314 unsigned long dirty,
90315@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
90316 }
90317 }
90318
90319-static struct notifier_block __cpuinitdata ratelimit_nb = {
90320+static struct notifier_block ratelimit_nb = {
90321 .notifier_call = ratelimit_handler,
90322 .next = NULL,
90323 };
90324diff --git a/mm/page_alloc.c b/mm/page_alloc.c
90325index 2ee0fd3..6e2edfb 100644
90326--- a/mm/page_alloc.c
90327+++ b/mm/page_alloc.c
90328@@ -60,6 +60,7 @@
90329 #include <linux/page-debug-flags.h>
90330 #include <linux/hugetlb.h>
90331 #include <linux/sched/rt.h>
90332+#include <linux/random.h>
90333
90334 #include <asm/tlbflush.h>
90335 #include <asm/div64.h>
90336@@ -345,7 +346,7 @@ out:
90337 * This usage means that zero-order pages may not be compound.
90338 */
90339
90340-static void free_compound_page(struct page *page)
90341+void free_compound_page(struct page *page)
90342 {
90343 __free_pages_ok(page, compound_order(page));
90344 }
90345@@ -702,6 +703,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90346 int i;
90347 int bad = 0;
90348
90349+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90350+ unsigned long index = 1UL << order;
90351+#endif
90352+
90353 trace_mm_page_free(page, order);
90354 kmemcheck_free_shadow(page, order);
90355
90356@@ -717,6 +722,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90357 debug_check_no_obj_freed(page_address(page),
90358 PAGE_SIZE << order);
90359 }
90360+
90361+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90362+ for (; index; --index)
90363+ sanitize_highpage(page + index - 1);
90364+#endif
90365+
90366 arch_free_page(page, order);
90367 kernel_map_pages(page, 1 << order, 0);
90368
90369@@ -739,6 +750,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
90370 local_irq_restore(flags);
90371 }
90372
90373+#ifdef CONFIG_PAX_LATENT_ENTROPY
90374+bool __meminitdata extra_latent_entropy;
90375+
90376+static int __init setup_pax_extra_latent_entropy(char *str)
90377+{
90378+ extra_latent_entropy = true;
90379+ return 0;
90380+}
90381+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
90382+
90383+volatile u64 latent_entropy;
90384+#endif
90385+
90386 /*
90387 * Read access to zone->managed_pages is safe because it's unsigned long,
90388 * but we still need to serialize writers. Currently all callers of
90389@@ -761,6 +785,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
90390 set_page_count(p, 0);
90391 }
90392
90393+#ifdef CONFIG_PAX_LATENT_ENTROPY
90394+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
90395+ u64 hash = 0;
90396+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
90397+ const u64 *data = lowmem_page_address(page);
90398+
90399+ for (index = 0; index < end; index++)
90400+ hash ^= hash + data[index];
90401+ latent_entropy ^= hash;
90402+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
90403+ }
90404+#endif
90405+
90406 page_zone(page)->managed_pages += 1 << order;
90407 set_page_refcounted(page);
90408 __free_pages(page, order);
90409@@ -870,8 +907,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
90410 arch_alloc_page(page, order);
90411 kernel_map_pages(page, 1 << order, 1);
90412
90413+#ifndef CONFIG_PAX_MEMORY_SANITIZE
90414 if (gfp_flags & __GFP_ZERO)
90415 prep_zero_page(page, order, gfp_flags);
90416+#endif
90417
90418 if (order && (gfp_flags & __GFP_COMP))
90419 prep_compound_page(page, order);
90420diff --git a/mm/page_io.c b/mm/page_io.c
90421index a8a3ef4..7260a60 100644
90422--- a/mm/page_io.c
90423+++ b/mm/page_io.c
90424@@ -214,7 +214,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
90425 struct file *swap_file = sis->swap_file;
90426 struct address_space *mapping = swap_file->f_mapping;
90427 struct iovec iov = {
90428- .iov_base = kmap(page),
90429+ .iov_base = (void __force_user *)kmap(page),
90430 .iov_len = PAGE_SIZE,
90431 };
90432
90433diff --git a/mm/percpu.c b/mm/percpu.c
90434index 8c8e08f..73a5cda 100644
90435--- a/mm/percpu.c
90436+++ b/mm/percpu.c
90437@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
90438 static unsigned int pcpu_high_unit_cpu __read_mostly;
90439
90440 /* the address of the first chunk which starts with the kernel static area */
90441-void *pcpu_base_addr __read_mostly;
90442+void *pcpu_base_addr __read_only;
90443 EXPORT_SYMBOL_GPL(pcpu_base_addr);
90444
90445 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
90446diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
90447index fd26d04..0cea1b0 100644
90448--- a/mm/process_vm_access.c
90449+++ b/mm/process_vm_access.c
90450@@ -13,6 +13,7 @@
90451 #include <linux/uio.h>
90452 #include <linux/sched.h>
90453 #include <linux/highmem.h>
90454+#include <linux/security.h>
90455 #include <linux/ptrace.h>
90456 #include <linux/slab.h>
90457 #include <linux/syscalls.h>
90458@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90459 size_t iov_l_curr_offset = 0;
90460 ssize_t iov_len;
90461
90462+ return -ENOSYS; // PaX: until properly audited
90463+
90464 /*
90465 * Work out how many pages of struct pages we're going to need
90466 * when eventually calling get_user_pages
90467 */
90468 for (i = 0; i < riovcnt; i++) {
90469 iov_len = rvec[i].iov_len;
90470- if (iov_len > 0) {
90471- nr_pages_iov = ((unsigned long)rvec[i].iov_base
90472- + iov_len)
90473- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
90474- / PAGE_SIZE + 1;
90475- nr_pages = max(nr_pages, nr_pages_iov);
90476- }
90477+ if (iov_len <= 0)
90478+ continue;
90479+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
90480+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
90481+ nr_pages = max(nr_pages, nr_pages_iov);
90482 }
90483
90484 if (nr_pages == 0)
90485@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90486 goto free_proc_pages;
90487 }
90488
90489+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
90490+ rc = -EPERM;
90491+ goto put_task_struct;
90492+ }
90493+
90494 mm = mm_access(task, PTRACE_MODE_ATTACH);
90495 if (!mm || IS_ERR(mm)) {
90496 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
90497diff --git a/mm/rmap.c b/mm/rmap.c
90498index 6280da8..b5c090e 100644
90499--- a/mm/rmap.c
90500+++ b/mm/rmap.c
90501@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90502 struct anon_vma *anon_vma = vma->anon_vma;
90503 struct anon_vma_chain *avc;
90504
90505+#ifdef CONFIG_PAX_SEGMEXEC
90506+ struct anon_vma_chain *avc_m = NULL;
90507+#endif
90508+
90509 might_sleep();
90510 if (unlikely(!anon_vma)) {
90511 struct mm_struct *mm = vma->vm_mm;
90512@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90513 if (!avc)
90514 goto out_enomem;
90515
90516+#ifdef CONFIG_PAX_SEGMEXEC
90517+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
90518+ if (!avc_m)
90519+ goto out_enomem_free_avc;
90520+#endif
90521+
90522 anon_vma = find_mergeable_anon_vma(vma);
90523 allocated = NULL;
90524 if (!anon_vma) {
90525@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90526 /* page_table_lock to protect against threads */
90527 spin_lock(&mm->page_table_lock);
90528 if (likely(!vma->anon_vma)) {
90529+
90530+#ifdef CONFIG_PAX_SEGMEXEC
90531+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
90532+
90533+ if (vma_m) {
90534+ BUG_ON(vma_m->anon_vma);
90535+ vma_m->anon_vma = anon_vma;
90536+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
90537+ avc_m = NULL;
90538+ }
90539+#endif
90540+
90541 vma->anon_vma = anon_vma;
90542 anon_vma_chain_link(vma, avc, anon_vma);
90543 allocated = NULL;
90544@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90545
90546 if (unlikely(allocated))
90547 put_anon_vma(allocated);
90548+
90549+#ifdef CONFIG_PAX_SEGMEXEC
90550+ if (unlikely(avc_m))
90551+ anon_vma_chain_free(avc_m);
90552+#endif
90553+
90554 if (unlikely(avc))
90555 anon_vma_chain_free(avc);
90556 }
90557 return 0;
90558
90559 out_enomem_free_avc:
90560+
90561+#ifdef CONFIG_PAX_SEGMEXEC
90562+ if (avc_m)
90563+ anon_vma_chain_free(avc_m);
90564+#endif
90565+
90566 anon_vma_chain_free(avc);
90567 out_enomem:
90568 return -ENOMEM;
90569@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
90570 * Attach the anon_vmas from src to dst.
90571 * Returns 0 on success, -ENOMEM on failure.
90572 */
90573-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90574+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
90575 {
90576 struct anon_vma_chain *avc, *pavc;
90577 struct anon_vma *root = NULL;
90578@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90579 * the corresponding VMA in the parent process is attached to.
90580 * Returns 0 on success, non-zero on failure.
90581 */
90582-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
90583+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
90584 {
90585 struct anon_vma_chain *avc;
90586 struct anon_vma *anon_vma;
90587@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
90588 void __init anon_vma_init(void)
90589 {
90590 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
90591- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
90592- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
90593+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
90594+ anon_vma_ctor);
90595+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
90596+ SLAB_PANIC|SLAB_NO_SANITIZE);
90597 }
90598
90599 /*
90600diff --git a/mm/shmem.c b/mm/shmem.c
90601index 5e6a842..b41916e 100644
90602--- a/mm/shmem.c
90603+++ b/mm/shmem.c
90604@@ -33,7 +33,7 @@
90605 #include <linux/swap.h>
90606 #include <linux/aio.h>
90607
90608-static struct vfsmount *shm_mnt;
90609+struct vfsmount *shm_mnt;
90610
90611 #ifdef CONFIG_SHMEM
90612 /*
90613@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
90614 #define BOGO_DIRENT_SIZE 20
90615
90616 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
90617-#define SHORT_SYMLINK_LEN 128
90618+#define SHORT_SYMLINK_LEN 64
90619
90620 /*
90621 * shmem_fallocate and shmem_writepage communicate via inode->i_private
90622@@ -2203,6 +2203,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
90623 static int shmem_xattr_validate(const char *name)
90624 {
90625 struct { const char *prefix; size_t len; } arr[] = {
90626+
90627+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90628+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
90629+#endif
90630+
90631 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
90632 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
90633 };
90634@@ -2258,6 +2263,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
90635 if (err)
90636 return err;
90637
90638+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90639+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
90640+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
90641+ return -EOPNOTSUPP;
90642+ if (size > 8)
90643+ return -EINVAL;
90644+ }
90645+#endif
90646+
90647 return simple_xattr_set(&info->xattrs, name, value, size, flags);
90648 }
90649
90650@@ -2570,8 +2584,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
90651 int err = -ENOMEM;
90652
90653 /* Round up to L1_CACHE_BYTES to resist false sharing */
90654- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
90655- L1_CACHE_BYTES), GFP_KERNEL);
90656+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
90657 if (!sbinfo)
90658 return -ENOMEM;
90659
90660diff --git a/mm/slab.c b/mm/slab.c
90661index bd88411..2d46fd6 100644
90662--- a/mm/slab.c
90663+++ b/mm/slab.c
90664@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90665 if ((x)->max_freeable < i) \
90666 (x)->max_freeable = i; \
90667 } while (0)
90668-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
90669-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
90670-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
90671-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
90672+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
90673+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
90674+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
90675+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
90676+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
90677+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
90678 #else
90679 #define STATS_INC_ACTIVE(x) do { } while (0)
90680 #define STATS_DEC_ACTIVE(x) do { } while (0)
90681@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90682 #define STATS_INC_ALLOCMISS(x) do { } while (0)
90683 #define STATS_INC_FREEHIT(x) do { } while (0)
90684 #define STATS_INC_FREEMISS(x) do { } while (0)
90685+#define STATS_INC_SANITIZED(x) do { } while (0)
90686+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
90687 #endif
90688
90689 #if DEBUG
90690@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
90691 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
90692 */
90693 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
90694- const struct slab *slab, void *obj)
90695+ const struct slab *slab, const void *obj)
90696 {
90697 u32 offset = (obj - slab->s_mem);
90698 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
90699@@ -1384,7 +1388,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
90700 return notifier_from_errno(err);
90701 }
90702
90703-static struct notifier_block __cpuinitdata cpucache_notifier = {
90704+static struct notifier_block cpucache_notifier = {
90705 &cpuup_callback, NULL, 0
90706 };
90707
90708@@ -1565,12 +1569,12 @@ void __init kmem_cache_init(void)
90709 */
90710
90711 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
90712- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
90713+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90714
90715 if (INDEX_AC != INDEX_NODE)
90716 kmalloc_caches[INDEX_NODE] =
90717 create_kmalloc_cache("kmalloc-node",
90718- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
90719+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90720
90721 slab_early_init = 0;
90722
90723@@ -3583,6 +3587,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
90724 struct array_cache *ac = cpu_cache_get(cachep);
90725
90726 check_irq_off();
90727+
90728+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90729+ if (pax_sanitize_slab) {
90730+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
90731+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
90732+
90733+ if (cachep->ctor)
90734+ cachep->ctor(objp);
90735+
90736+ STATS_INC_SANITIZED(cachep);
90737+ } else
90738+ STATS_INC_NOT_SANITIZED(cachep);
90739+ }
90740+#endif
90741+
90742 kmemleak_free_recursive(objp, cachep->flags);
90743 objp = cache_free_debugcheck(cachep, objp, caller);
90744
90745@@ -3800,6 +3819,7 @@ void kfree(const void *objp)
90746
90747 if (unlikely(ZERO_OR_NULL_PTR(objp)))
90748 return;
90749+ VM_BUG_ON(!virt_addr_valid(objp));
90750 local_irq_save(flags);
90751 kfree_debugcheck(objp);
90752 c = virt_to_cache(objp);
90753@@ -4241,14 +4261,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
90754 }
90755 /* cpu stats */
90756 {
90757- unsigned long allochit = atomic_read(&cachep->allochit);
90758- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
90759- unsigned long freehit = atomic_read(&cachep->freehit);
90760- unsigned long freemiss = atomic_read(&cachep->freemiss);
90761+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
90762+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
90763+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
90764+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
90765
90766 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
90767 allochit, allocmiss, freehit, freemiss);
90768 }
90769+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90770+ {
90771+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
90772+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
90773+
90774+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
90775+ }
90776+#endif
90777 #endif
90778 }
90779
90780@@ -4476,13 +4504,71 @@ static const struct file_operations proc_slabstats_operations = {
90781 static int __init slab_proc_init(void)
90782 {
90783 #ifdef CONFIG_DEBUG_SLAB_LEAK
90784- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
90785+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
90786 #endif
90787 return 0;
90788 }
90789 module_init(slab_proc_init);
90790 #endif
90791
90792+bool is_usercopy_object(const void *ptr)
90793+{
90794+ struct page *page;
90795+ struct kmem_cache *cachep;
90796+
90797+ if (ZERO_OR_NULL_PTR(ptr))
90798+ return false;
90799+
90800+ if (!slab_is_available())
90801+ return false;
90802+
90803+ if (!virt_addr_valid(ptr))
90804+ return false;
90805+
90806+ page = virt_to_head_page(ptr);
90807+
90808+ if (!PageSlab(page))
90809+ return false;
90810+
90811+ cachep = page->slab_cache;
90812+ return cachep->flags & SLAB_USERCOPY;
90813+}
90814+
90815+#ifdef CONFIG_PAX_USERCOPY
90816+const char *check_heap_object(const void *ptr, unsigned long n)
90817+{
90818+ struct page *page;
90819+ struct kmem_cache *cachep;
90820+ struct slab *slabp;
90821+ unsigned int objnr;
90822+ unsigned long offset;
90823+
90824+ if (ZERO_OR_NULL_PTR(ptr))
90825+ return "<null>";
90826+
90827+ if (!virt_addr_valid(ptr))
90828+ return NULL;
90829+
90830+ page = virt_to_head_page(ptr);
90831+
90832+ if (!PageSlab(page))
90833+ return NULL;
90834+
90835+ cachep = page->slab_cache;
90836+ if (!(cachep->flags & SLAB_USERCOPY))
90837+ return cachep->name;
90838+
90839+ slabp = page->slab_page;
90840+ objnr = obj_to_index(cachep, slabp, ptr);
90841+ BUG_ON(objnr >= cachep->num);
90842+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
90843+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
90844+ return NULL;
90845+
90846+ return cachep->name;
90847+}
90848+#endif
90849+
90850 /**
90851 * ksize - get the actual amount of memory allocated for a given object
90852 * @objp: Pointer to the object
90853diff --git a/mm/slab.h b/mm/slab.h
90854index f96b49e..db1d204 100644
90855--- a/mm/slab.h
90856+++ b/mm/slab.h
90857@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
90858 /* The slab cache that manages slab cache information */
90859 extern struct kmem_cache *kmem_cache;
90860
90861+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90862+#ifdef CONFIG_X86_64
90863+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
90864+#else
90865+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
90866+#endif
90867+extern bool pax_sanitize_slab;
90868+#endif
90869+
90870 unsigned long calculate_alignment(unsigned long flags,
90871 unsigned long align, unsigned long size);
90872
90873@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90874
90875 /* Legal flag mask for kmem_cache_create(), for various configurations */
90876 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
90877- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
90878+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
90879+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
90880
90881 #if defined(CONFIG_DEBUG_SLAB)
90882 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
90883@@ -229,6 +239,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
90884 return s;
90885
90886 page = virt_to_head_page(x);
90887+
90888+ BUG_ON(!PageSlab(page));
90889+
90890 cachep = page->slab_cache;
90891 if (slab_equal_or_root(cachep, s))
90892 return cachep;
90893diff --git a/mm/slab_common.c b/mm/slab_common.c
90894index 2d41450..4efe6ee 100644
90895--- a/mm/slab_common.c
90896+++ b/mm/slab_common.c
90897@@ -22,11 +22,22 @@
90898
90899 #include "slab.h"
90900
90901-enum slab_state slab_state;
90902+enum slab_state slab_state __read_only;
90903 LIST_HEAD(slab_caches);
90904 DEFINE_MUTEX(slab_mutex);
90905 struct kmem_cache *kmem_cache;
90906
90907+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90908+bool pax_sanitize_slab __read_only = true;
90909+static int __init pax_sanitize_slab_setup(char *str)
90910+{
90911+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
90912+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
90913+ return 1;
90914+}
90915+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
90916+#endif
90917+
90918 #ifdef CONFIG_DEBUG_VM
90919 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
90920 size_t size)
90921@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
90922
90923 err = __kmem_cache_create(s, flags);
90924 if (!err) {
90925- s->refcount = 1;
90926+ atomic_set(&s->refcount, 1);
90927 list_add(&s->list, &slab_caches);
90928 memcg_cache_list_add(memcg, s);
90929 } else {
90930@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
90931
90932 get_online_cpus();
90933 mutex_lock(&slab_mutex);
90934- s->refcount--;
90935- if (!s->refcount) {
90936+ if (atomic_dec_and_test(&s->refcount)) {
90937 list_del(&s->list);
90938
90939 if (!__kmem_cache_shutdown(s)) {
90940@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
90941 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
90942 name, size, err);
90943
90944- s->refcount = -1; /* Exempt from merging for now */
90945+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
90946 }
90947
90948 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90949@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90950
90951 create_boot_cache(s, name, size, flags);
90952 list_add(&s->list, &slab_caches);
90953- s->refcount = 1;
90954+ atomic_set(&s->refcount, 1);
90955 return s;
90956 }
90957
90958@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
90959 EXPORT_SYMBOL(kmalloc_dma_caches);
90960 #endif
90961
90962+#ifdef CONFIG_PAX_USERCOPY_SLABS
90963+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
90964+EXPORT_SYMBOL(kmalloc_usercopy_caches);
90965+#endif
90966+
90967 /*
90968 * Conversion table for small slabs sizes / 8 to the index in the
90969 * kmalloc array. This is necessary for slabs < 192 since we have non power
90970@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
90971 return kmalloc_dma_caches[index];
90972
90973 #endif
90974+
90975+#ifdef CONFIG_PAX_USERCOPY_SLABS
90976+ if (unlikely((flags & GFP_USERCOPY)))
90977+ return kmalloc_usercopy_caches[index];
90978+
90979+#endif
90980+
90981 return kmalloc_caches[index];
90982 }
90983
90984@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
90985 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
90986 if (!kmalloc_caches[i]) {
90987 kmalloc_caches[i] = create_kmalloc_cache(NULL,
90988- 1 << i, flags);
90989+ 1 << i, SLAB_USERCOPY | flags);
90990 }
90991
90992 /*
90993@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
90994 * earlier power of two caches
90995 */
90996 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
90997- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
90998+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
90999
91000 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
91001- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
91002+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
91003 }
91004
91005 /* Kmalloc array is now usable */
91006@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
91007 }
91008 }
91009 #endif
91010+
91011+#ifdef CONFIG_PAX_USERCOPY_SLABS
91012+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
91013+ struct kmem_cache *s = kmalloc_caches[i];
91014+
91015+ if (s) {
91016+ int size = kmalloc_size(i);
91017+ char *n = kasprintf(GFP_NOWAIT,
91018+ "usercopy-kmalloc-%d", size);
91019+
91020+ BUG_ON(!n);
91021+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
91022+ size, SLAB_USERCOPY | flags);
91023+ }
91024+ }
91025+#endif
91026+
91027 }
91028 #endif /* !CONFIG_SLOB */
91029
91030@@ -516,6 +555,9 @@ void print_slabinfo_header(struct seq_file *m)
91031 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
91032 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
91033 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
91034+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91035+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
91036+#endif
91037 #endif
91038 seq_putc(m, '\n');
91039 }
91040diff --git a/mm/slob.c b/mm/slob.c
91041index eeed4a0..bb0e9ab 100644
91042--- a/mm/slob.c
91043+++ b/mm/slob.c
91044@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
91045 /*
91046 * Return the size of a slob block.
91047 */
91048-static slobidx_t slob_units(slob_t *s)
91049+static slobidx_t slob_units(const slob_t *s)
91050 {
91051 if (s->units > 0)
91052 return s->units;
91053@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
91054 /*
91055 * Return the next free slob block pointer after this one.
91056 */
91057-static slob_t *slob_next(slob_t *s)
91058+static slob_t *slob_next(const slob_t *s)
91059 {
91060 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
91061 slobidx_t next;
91062@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
91063 /*
91064 * Returns true if s is the last free block in its page.
91065 */
91066-static int slob_last(slob_t *s)
91067+static int slob_last(const slob_t *s)
91068 {
91069 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
91070 }
91071
91072-static void *slob_new_pages(gfp_t gfp, int order, int node)
91073+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
91074 {
91075- void *page;
91076+ struct page *page;
91077
91078 #ifdef CONFIG_NUMA
91079 if (node != NUMA_NO_NODE)
91080@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
91081 if (!page)
91082 return NULL;
91083
91084- return page_address(page);
91085+ __SetPageSlab(page);
91086+ return page;
91087 }
91088
91089-static void slob_free_pages(void *b, int order)
91090+static void slob_free_pages(struct page *sp, int order)
91091 {
91092 if (current->reclaim_state)
91093 current->reclaim_state->reclaimed_slab += 1 << order;
91094- free_pages((unsigned long)b, order);
91095+ __ClearPageSlab(sp);
91096+ page_mapcount_reset(sp);
91097+ sp->private = 0;
91098+ __free_pages(sp, order);
91099 }
91100
91101 /*
91102@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
91103
91104 /* Not enough space: must allocate a new page */
91105 if (!b) {
91106- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91107- if (!b)
91108+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
91109+ if (!sp)
91110 return NULL;
91111- sp = virt_to_page(b);
91112- __SetPageSlab(sp);
91113+ b = page_address(sp);
91114
91115 spin_lock_irqsave(&slob_lock, flags);
91116 sp->units = SLOB_UNITS(PAGE_SIZE);
91117 sp->freelist = b;
91118+ sp->private = 0;
91119 INIT_LIST_HEAD(&sp->list);
91120 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
91121 set_slob_page_free(sp, slob_list);
91122@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
91123 if (slob_page_free(sp))
91124 clear_slob_page_free(sp);
91125 spin_unlock_irqrestore(&slob_lock, flags);
91126- __ClearPageSlab(sp);
91127- page_mapcount_reset(sp);
91128- slob_free_pages(b, 0);
91129+ slob_free_pages(sp, 0);
91130 return;
91131 }
91132
91133+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91134+ if (pax_sanitize_slab)
91135+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
91136+#endif
91137+
91138 if (!slob_page_free(sp)) {
91139 /* This slob page is about to become partially free. Easy! */
91140 sp->units = units;
91141@@ -424,11 +431,10 @@ out:
91142 */
91143
91144 static __always_inline void *
91145-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91146+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
91147 {
91148- unsigned int *m;
91149- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91150- void *ret;
91151+ slob_t *m;
91152+ void *ret = NULL;
91153
91154 gfp &= gfp_allowed_mask;
91155
91156@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91157
91158 if (!m)
91159 return NULL;
91160- *m = size;
91161+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
91162+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
91163+ m[0].units = size;
91164+ m[1].units = align;
91165 ret = (void *)m + align;
91166
91167 trace_kmalloc_node(caller, ret,
91168 size, size + align, gfp, node);
91169 } else {
91170 unsigned int order = get_order(size);
91171+ struct page *page;
91172
91173 if (likely(order))
91174 gfp |= __GFP_COMP;
91175- ret = slob_new_pages(gfp, order, node);
91176+ page = slob_new_pages(gfp, order, node);
91177+ if (page) {
91178+ ret = page_address(page);
91179+ page->private = size;
91180+ }
91181
91182 trace_kmalloc_node(caller, ret,
91183 size, PAGE_SIZE << order, gfp, node);
91184 }
91185
91186- kmemleak_alloc(ret, size, 1, gfp);
91187+ return ret;
91188+}
91189+
91190+static __always_inline void *
91191+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
91192+{
91193+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91194+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
91195+
91196+ if (!ZERO_OR_NULL_PTR(ret))
91197+ kmemleak_alloc(ret, size, 1, gfp);
91198 return ret;
91199 }
91200
91201@@ -493,34 +517,112 @@ void kfree(const void *block)
91202 return;
91203 kmemleak_free(block);
91204
91205+ VM_BUG_ON(!virt_addr_valid(block));
91206 sp = virt_to_page(block);
91207- if (PageSlab(sp)) {
91208+ VM_BUG_ON(!PageSlab(sp));
91209+ if (!sp->private) {
91210 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91211- unsigned int *m = (unsigned int *)(block - align);
91212- slob_free(m, *m + align);
91213- } else
91214+ slob_t *m = (slob_t *)(block - align);
91215+ slob_free(m, m[0].units + align);
91216+ } else {
91217+ __ClearPageSlab(sp);
91218+ page_mapcount_reset(sp);
91219+ sp->private = 0;
91220 __free_pages(sp, compound_order(sp));
91221+ }
91222 }
91223 EXPORT_SYMBOL(kfree);
91224
91225+bool is_usercopy_object(const void *ptr)
91226+{
91227+ if (!slab_is_available())
91228+ return false;
91229+
91230+ // PAX: TODO
91231+
91232+ return false;
91233+}
91234+
91235+#ifdef CONFIG_PAX_USERCOPY
91236+const char *check_heap_object(const void *ptr, unsigned long n)
91237+{
91238+ struct page *page;
91239+ const slob_t *free;
91240+ const void *base;
91241+ unsigned long flags;
91242+
91243+ if (ZERO_OR_NULL_PTR(ptr))
91244+ return "<null>";
91245+
91246+ if (!virt_addr_valid(ptr))
91247+ return NULL;
91248+
91249+ page = virt_to_head_page(ptr);
91250+ if (!PageSlab(page))
91251+ return NULL;
91252+
91253+ if (page->private) {
91254+ base = page;
91255+ if (base <= ptr && n <= page->private - (ptr - base))
91256+ return NULL;
91257+ return "<slob>";
91258+ }
91259+
91260+ /* some tricky double walking to find the chunk */
91261+ spin_lock_irqsave(&slob_lock, flags);
91262+ base = (void *)((unsigned long)ptr & PAGE_MASK);
91263+ free = page->freelist;
91264+
91265+ while (!slob_last(free) && (void *)free <= ptr) {
91266+ base = free + slob_units(free);
91267+ free = slob_next(free);
91268+ }
91269+
91270+ while (base < (void *)free) {
91271+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
91272+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
91273+ int offset;
91274+
91275+ if (ptr < base + align)
91276+ break;
91277+
91278+ offset = ptr - base - align;
91279+ if (offset >= m) {
91280+ base += size;
91281+ continue;
91282+ }
91283+
91284+ if (n > m - offset)
91285+ break;
91286+
91287+ spin_unlock_irqrestore(&slob_lock, flags);
91288+ return NULL;
91289+ }
91290+
91291+ spin_unlock_irqrestore(&slob_lock, flags);
91292+ return "<slob>";
91293+}
91294+#endif
91295+
91296 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
91297 size_t ksize(const void *block)
91298 {
91299 struct page *sp;
91300 int align;
91301- unsigned int *m;
91302+ slob_t *m;
91303
91304 BUG_ON(!block);
91305 if (unlikely(block == ZERO_SIZE_PTR))
91306 return 0;
91307
91308 sp = virt_to_page(block);
91309- if (unlikely(!PageSlab(sp)))
91310- return PAGE_SIZE << compound_order(sp);
91311+ VM_BUG_ON(!PageSlab(sp));
91312+ if (sp->private)
91313+ return sp->private;
91314
91315 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91316- m = (unsigned int *)(block - align);
91317- return SLOB_UNITS(*m) * SLOB_UNIT;
91318+ m = (slob_t *)(block - align);
91319+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
91320 }
91321 EXPORT_SYMBOL(ksize);
91322
91323@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
91324
91325 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
91326 {
91327- void *b;
91328+ void *b = NULL;
91329
91330 flags &= gfp_allowed_mask;
91331
91332 lockdep_trace_alloc(flags);
91333
91334+#ifdef CONFIG_PAX_USERCOPY_SLABS
91335+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
91336+#else
91337 if (c->size < PAGE_SIZE) {
91338 b = slob_alloc(c->size, flags, c->align, node);
91339 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91340 SLOB_UNITS(c->size) * SLOB_UNIT,
91341 flags, node);
91342 } else {
91343- b = slob_new_pages(flags, get_order(c->size), node);
91344+ struct page *sp;
91345+
91346+ sp = slob_new_pages(flags, get_order(c->size), node);
91347+ if (sp) {
91348+ b = page_address(sp);
91349+ sp->private = c->size;
91350+ }
91351 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91352 PAGE_SIZE << get_order(c->size),
91353 flags, node);
91354 }
91355+#endif
91356
91357 if (c->ctor)
91358 c->ctor(b);
91359@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
91360
91361 static void __kmem_cache_free(void *b, int size)
91362 {
91363- if (size < PAGE_SIZE)
91364+ struct page *sp;
91365+
91366+ sp = virt_to_page(b);
91367+ BUG_ON(!PageSlab(sp));
91368+ if (!sp->private)
91369 slob_free(b, size);
91370 else
91371- slob_free_pages(b, get_order(size));
91372+ slob_free_pages(sp, get_order(size));
91373 }
91374
91375 static void kmem_rcu_free(struct rcu_head *head)
91376@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
91377
91378 void kmem_cache_free(struct kmem_cache *c, void *b)
91379 {
91380+ int size = c->size;
91381+
91382+#ifdef CONFIG_PAX_USERCOPY_SLABS
91383+ if (size + c->align < PAGE_SIZE) {
91384+ size += c->align;
91385+ b -= c->align;
91386+ }
91387+#endif
91388+
91389 kmemleak_free_recursive(b, c->flags);
91390 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
91391 struct slob_rcu *slob_rcu;
91392- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
91393- slob_rcu->size = c->size;
91394+ slob_rcu = b + (size - sizeof(struct slob_rcu));
91395+ slob_rcu->size = size;
91396 call_rcu(&slob_rcu->head, kmem_rcu_free);
91397 } else {
91398- __kmem_cache_free(b, c->size);
91399+ __kmem_cache_free(b, size);
91400 }
91401
91402+#ifdef CONFIG_PAX_USERCOPY_SLABS
91403+ trace_kfree(_RET_IP_, b);
91404+#else
91405 trace_kmem_cache_free(_RET_IP_, b);
91406+#endif
91407+
91408 }
91409 EXPORT_SYMBOL(kmem_cache_free);
91410
91411diff --git a/mm/slub.c b/mm/slub.c
91412index 57707f0..7857bd3 100644
91413--- a/mm/slub.c
91414+++ b/mm/slub.c
91415@@ -198,7 +198,7 @@ struct track {
91416
91417 enum track_item { TRACK_ALLOC, TRACK_FREE };
91418
91419-#ifdef CONFIG_SYSFS
91420+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91421 static int sysfs_slab_add(struct kmem_cache *);
91422 static int sysfs_slab_alias(struct kmem_cache *, const char *);
91423 static void sysfs_slab_remove(struct kmem_cache *);
91424@@ -519,7 +519,7 @@ static void print_track(const char *s, struct track *t)
91425 if (!t->addr)
91426 return;
91427
91428- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
91429+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
91430 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
91431 #ifdef CONFIG_STACKTRACE
91432 {
91433@@ -2594,6 +2594,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
91434
91435 slab_free_hook(s, x);
91436
91437+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91438+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
91439+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
91440+ if (s->ctor)
91441+ s->ctor(x);
91442+ }
91443+#endif
91444+
91445 redo:
91446 /*
91447 * Determine the currently cpus per cpu slab.
91448@@ -2661,7 +2669,7 @@ static int slub_min_objects;
91449 * Merge control. If this is set then no merging of slab caches will occur.
91450 * (Could be removed. This was introduced to pacify the merge skeptics.)
91451 */
91452-static int slub_nomerge;
91453+static int slub_nomerge = 1;
91454
91455 /*
91456 * Calculate the order of allocation given an slab object size.
91457@@ -2938,6 +2946,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
91458 s->inuse = size;
91459
91460 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
91461+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91462+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
91463+#endif
91464 s->ctor)) {
91465 /*
91466 * Relocate free pointer after the object if it is not
91467@@ -3283,6 +3294,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
91468 EXPORT_SYMBOL(__kmalloc_node);
91469 #endif
91470
91471+bool is_usercopy_object(const void *ptr)
91472+{
91473+ struct page *page;
91474+ struct kmem_cache *s;
91475+
91476+ if (ZERO_OR_NULL_PTR(ptr))
91477+ return false;
91478+
91479+ if (!slab_is_available())
91480+ return false;
91481+
91482+ if (!virt_addr_valid(ptr))
91483+ return false;
91484+
91485+ page = virt_to_head_page(ptr);
91486+
91487+ if (!PageSlab(page))
91488+ return false;
91489+
91490+ s = page->slab_cache;
91491+ return s->flags & SLAB_USERCOPY;
91492+}
91493+
91494+#ifdef CONFIG_PAX_USERCOPY
91495+const char *check_heap_object(const void *ptr, unsigned long n)
91496+{
91497+ struct page *page;
91498+ struct kmem_cache *s;
91499+ unsigned long offset;
91500+
91501+ if (ZERO_OR_NULL_PTR(ptr))
91502+ return "<null>";
91503+
91504+ if (!virt_addr_valid(ptr))
91505+ return NULL;
91506+
91507+ page = virt_to_head_page(ptr);
91508+
91509+ if (!PageSlab(page))
91510+ return NULL;
91511+
91512+ s = page->slab_cache;
91513+ if (!(s->flags & SLAB_USERCOPY))
91514+ return s->name;
91515+
91516+ offset = (ptr - page_address(page)) % s->size;
91517+ if (offset <= s->object_size && n <= s->object_size - offset)
91518+ return NULL;
91519+
91520+ return s->name;
91521+}
91522+#endif
91523+
91524 size_t ksize(const void *object)
91525 {
91526 struct page *page;
91527@@ -3347,6 +3411,7 @@ void kfree(const void *x)
91528 if (unlikely(ZERO_OR_NULL_PTR(x)))
91529 return;
91530
91531+ VM_BUG_ON(!virt_addr_valid(x));
91532 page = virt_to_head_page(x);
91533 if (unlikely(!PageSlab(page))) {
91534 BUG_ON(!PageCompound(page));
91535@@ -3652,7 +3717,7 @@ static int slab_unmergeable(struct kmem_cache *s)
91536 /*
91537 * We may have set a slab to be unmergeable during bootstrap.
91538 */
91539- if (s->refcount < 0)
91540+ if (atomic_read(&s->refcount) < 0)
91541 return 1;
91542
91543 return 0;
91544@@ -3710,7 +3775,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91545
91546 s = find_mergeable(memcg, size, align, flags, name, ctor);
91547 if (s) {
91548- s->refcount++;
91549+ atomic_inc(&s->refcount);
91550 /*
91551 * Adjust the object sizes so that we clear
91552 * the complete object on kzalloc.
91553@@ -3719,7 +3784,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91554 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
91555
91556 if (sysfs_slab_alias(s, name)) {
91557- s->refcount--;
91558+ atomic_dec(&s->refcount);
91559 s = NULL;
91560 }
91561 }
91562@@ -3781,7 +3846,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
91563 return NOTIFY_OK;
91564 }
91565
91566-static struct notifier_block __cpuinitdata slab_notifier = {
91567+static struct notifier_block slab_notifier = {
91568 .notifier_call = slab_cpuup_callback
91569 };
91570
91571@@ -3839,7 +3904,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
91572 }
91573 #endif
91574
91575-#ifdef CONFIG_SYSFS
91576+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91577 static int count_inuse(struct page *page)
91578 {
91579 return page->inuse;
91580@@ -4226,12 +4291,12 @@ static void resiliency_test(void)
91581 validate_slab_cache(kmalloc_caches[9]);
91582 }
91583 #else
91584-#ifdef CONFIG_SYSFS
91585+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91586 static void resiliency_test(void) {};
91587 #endif
91588 #endif
91589
91590-#ifdef CONFIG_SYSFS
91591+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91592 enum slab_stat_type {
91593 SL_ALL, /* All slabs */
91594 SL_PARTIAL, /* Only partially allocated slabs */
91595@@ -4475,7 +4540,7 @@ SLAB_ATTR_RO(ctor);
91596
91597 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
91598 {
91599- return sprintf(buf, "%d\n", s->refcount - 1);
91600+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
91601 }
91602 SLAB_ATTR_RO(aliases);
91603
91604@@ -4563,6 +4628,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
91605 SLAB_ATTR_RO(cache_dma);
91606 #endif
91607
91608+#ifdef CONFIG_PAX_USERCOPY_SLABS
91609+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
91610+{
91611+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
91612+}
91613+SLAB_ATTR_RO(usercopy);
91614+#endif
91615+
91616 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
91617 {
91618 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
91619@@ -4897,6 +4970,9 @@ static struct attribute *slab_attrs[] = {
91620 #ifdef CONFIG_ZONE_DMA
91621 &cache_dma_attr.attr,
91622 #endif
91623+#ifdef CONFIG_PAX_USERCOPY_SLABS
91624+ &usercopy_attr.attr,
91625+#endif
91626 #ifdef CONFIG_NUMA
91627 &remote_node_defrag_ratio_attr.attr,
91628 #endif
91629@@ -5128,6 +5204,7 @@ static char *create_unique_id(struct kmem_cache *s)
91630 return name;
91631 }
91632
91633+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91634 static int sysfs_slab_add(struct kmem_cache *s)
91635 {
91636 int err;
91637@@ -5151,7 +5228,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
91638 }
91639
91640 s->kobj.kset = slab_kset;
91641- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
91642+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
91643 if (err) {
91644 kobject_put(&s->kobj);
91645 return err;
91646@@ -5185,6 +5262,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
91647 kobject_del(&s->kobj);
91648 kobject_put(&s->kobj);
91649 }
91650+#endif
91651
91652 /*
91653 * Need to buffer aliases during bootup until sysfs becomes
91654@@ -5198,6 +5276,7 @@ struct saved_alias {
91655
91656 static struct saved_alias *alias_list;
91657
91658+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91659 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91660 {
91661 struct saved_alias *al;
91662@@ -5220,6 +5299,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91663 alias_list = al;
91664 return 0;
91665 }
91666+#endif
91667
91668 static int __init slab_sysfs_init(void)
91669 {
91670diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
91671index 27eeab3..7c3f7f2 100644
91672--- a/mm/sparse-vmemmap.c
91673+++ b/mm/sparse-vmemmap.c
91674@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
91675 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91676 if (!p)
91677 return NULL;
91678- pud_populate(&init_mm, pud, p);
91679+ pud_populate_kernel(&init_mm, pud, p);
91680 }
91681 return pud;
91682 }
91683@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
91684 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91685 if (!p)
91686 return NULL;
91687- pgd_populate(&init_mm, pgd, p);
91688+ pgd_populate_kernel(&init_mm, pgd, p);
91689 }
91690 return pgd;
91691 }
91692diff --git a/mm/sparse.c b/mm/sparse.c
91693index 1c91f0d3..485470a 100644
91694--- a/mm/sparse.c
91695+++ b/mm/sparse.c
91696@@ -761,7 +761,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
91697
91698 for (i = 0; i < PAGES_PER_SECTION; i++) {
91699 if (PageHWPoison(&memmap[i])) {
91700- atomic_long_sub(1, &num_poisoned_pages);
91701+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
91702 ClearPageHWPoison(&memmap[i]);
91703 }
91704 }
91705diff --git a/mm/swap.c b/mm/swap.c
91706index dfd7d71..ccdf688 100644
91707--- a/mm/swap.c
91708+++ b/mm/swap.c
91709@@ -31,6 +31,7 @@
91710 #include <linux/memcontrol.h>
91711 #include <linux/gfp.h>
91712 #include <linux/uio.h>
91713+#include <linux/hugetlb.h>
91714
91715 #include "internal.h"
91716
91717@@ -73,6 +74,8 @@ static void __put_compound_page(struct page *page)
91718
91719 __page_cache_release(page);
91720 dtor = get_compound_page_dtor(page);
91721+ if (!PageHuge(page))
91722+ BUG_ON(dtor != free_compound_page);
91723 (*dtor)(page);
91724 }
91725
91726diff --git a/mm/swapfile.c b/mm/swapfile.c
91727index 746af55b..7ac94ae 100644
91728--- a/mm/swapfile.c
91729+++ b/mm/swapfile.c
91730@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
91731
91732 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
91733 /* Activity counter to indicate that a swapon or swapoff has occurred */
91734-static atomic_t proc_poll_event = ATOMIC_INIT(0);
91735+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
91736
91737 static inline unsigned char swap_count(unsigned char ent)
91738 {
91739@@ -1684,7 +1684,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
91740 }
91741 filp_close(swap_file, NULL);
91742 err = 0;
91743- atomic_inc(&proc_poll_event);
91744+ atomic_inc_unchecked(&proc_poll_event);
91745 wake_up_interruptible(&proc_poll_wait);
91746
91747 out_dput:
91748@@ -1701,8 +1701,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
91749
91750 poll_wait(file, &proc_poll_wait, wait);
91751
91752- if (seq->poll_event != atomic_read(&proc_poll_event)) {
91753- seq->poll_event = atomic_read(&proc_poll_event);
91754+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
91755+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91756 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
91757 }
91758
91759@@ -1800,7 +1800,7 @@ static int swaps_open(struct inode *inode, struct file *file)
91760 return ret;
91761
91762 seq = file->private_data;
91763- seq->poll_event = atomic_read(&proc_poll_event);
91764+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91765 return 0;
91766 }
91767
91768@@ -2143,7 +2143,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
91769 (frontswap_map) ? "FS" : "");
91770
91771 mutex_unlock(&swapon_mutex);
91772- atomic_inc(&proc_poll_event);
91773+ atomic_inc_unchecked(&proc_poll_event);
91774 wake_up_interruptible(&proc_poll_wait);
91775
91776 if (S_ISREG(inode->i_mode))
91777diff --git a/mm/util.c b/mm/util.c
91778index ab1424d..7c5bd5a 100644
91779--- a/mm/util.c
91780+++ b/mm/util.c
91781@@ -294,6 +294,12 @@ done:
91782 void arch_pick_mmap_layout(struct mm_struct *mm)
91783 {
91784 mm->mmap_base = TASK_UNMAPPED_BASE;
91785+
91786+#ifdef CONFIG_PAX_RANDMMAP
91787+ if (mm->pax_flags & MF_PAX_RANDMMAP)
91788+ mm->mmap_base += mm->delta_mmap;
91789+#endif
91790+
91791 mm->get_unmapped_area = arch_get_unmapped_area;
91792 mm->unmap_area = arch_unmap_area;
91793 }
91794diff --git a/mm/vmalloc.c b/mm/vmalloc.c
91795index d365724..6cae7c2 100644
91796--- a/mm/vmalloc.c
91797+++ b/mm/vmalloc.c
91798@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
91799
91800 pte = pte_offset_kernel(pmd, addr);
91801 do {
91802- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91803- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91804+
91805+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91806+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
91807+ BUG_ON(!pte_exec(*pte));
91808+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
91809+ continue;
91810+ }
91811+#endif
91812+
91813+ {
91814+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91815+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91816+ }
91817 } while (pte++, addr += PAGE_SIZE, addr != end);
91818 }
91819
91820@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
91821 pte = pte_alloc_kernel(pmd, addr);
91822 if (!pte)
91823 return -ENOMEM;
91824+
91825+ pax_open_kernel();
91826 do {
91827 struct page *page = pages[*nr];
91828
91829- if (WARN_ON(!pte_none(*pte)))
91830+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91831+ if (pgprot_val(prot) & _PAGE_NX)
91832+#endif
91833+
91834+ if (!pte_none(*pte)) {
91835+ pax_close_kernel();
91836+ WARN_ON(1);
91837 return -EBUSY;
91838- if (WARN_ON(!page))
91839+ }
91840+ if (!page) {
91841+ pax_close_kernel();
91842+ WARN_ON(1);
91843 return -ENOMEM;
91844+ }
91845 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
91846 (*nr)++;
91847 } while (pte++, addr += PAGE_SIZE, addr != end);
91848+ pax_close_kernel();
91849 return 0;
91850 }
91851
91852@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
91853 pmd_t *pmd;
91854 unsigned long next;
91855
91856- pmd = pmd_alloc(&init_mm, pud, addr);
91857+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91858 if (!pmd)
91859 return -ENOMEM;
91860 do {
91861@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
91862 pud_t *pud;
91863 unsigned long next;
91864
91865- pud = pud_alloc(&init_mm, pgd, addr);
91866+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91867 if (!pud)
91868 return -ENOMEM;
91869 do {
91870@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
91871 if (addr >= MODULES_VADDR && addr < MODULES_END)
91872 return 1;
91873 #endif
91874+
91875+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91876+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
91877+ return 1;
91878+#endif
91879+
91880 return is_vmalloc_addr(x);
91881 }
91882
91883@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
91884
91885 if (!pgd_none(*pgd)) {
91886 pud_t *pud = pud_offset(pgd, addr);
91887+#ifdef CONFIG_X86
91888+ if (!pud_large(*pud))
91889+#endif
91890 if (!pud_none(*pud)) {
91891 pmd_t *pmd = pmd_offset(pud, addr);
91892+#ifdef CONFIG_X86
91893+ if (!pmd_large(*pmd))
91894+#endif
91895 if (!pmd_none(*pmd)) {
91896 pte_t *ptep, pte;
91897
91898@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
91899 * Allocate a region of KVA of the specified size and alignment, within the
91900 * vstart and vend.
91901 */
91902-static struct vmap_area *alloc_vmap_area(unsigned long size,
91903+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
91904 unsigned long align,
91905 unsigned long vstart, unsigned long vend,
91906 int node, gfp_t gfp_mask)
91907@@ -1337,6 +1373,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
91908 struct vm_struct *area;
91909
91910 BUG_ON(in_interrupt());
91911+
91912+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91913+ if (flags & VM_KERNEXEC) {
91914+ if (start != VMALLOC_START || end != VMALLOC_END)
91915+ return NULL;
91916+ start = (unsigned long)MODULES_EXEC_VADDR;
91917+ end = (unsigned long)MODULES_EXEC_END;
91918+ }
91919+#endif
91920+
91921 if (flags & VM_IOREMAP) {
91922 int bit = fls(size);
91923
91924@@ -1581,6 +1627,11 @@ void *vmap(struct page **pages, unsigned int count,
91925 if (count > totalram_pages)
91926 return NULL;
91927
91928+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91929+ if (!(pgprot_val(prot) & _PAGE_NX))
91930+ flags |= VM_KERNEXEC;
91931+#endif
91932+
91933 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
91934 __builtin_return_address(0));
91935 if (!area)
91936@@ -1682,6 +1733,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
91937 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
91938 goto fail;
91939
91940+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91941+ if (!(pgprot_val(prot) & _PAGE_NX))
91942+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
91943+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
91944+ else
91945+#endif
91946+
91947 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
91948 start, end, node, gfp_mask, caller);
91949 if (!area)
91950@@ -1858,10 +1916,9 @@ EXPORT_SYMBOL(vzalloc_node);
91951 * For tight control over page level allocator and protection flags
91952 * use __vmalloc() instead.
91953 */
91954-
91955 void *vmalloc_exec(unsigned long size)
91956 {
91957- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
91958+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
91959 NUMA_NO_NODE, __builtin_return_address(0));
91960 }
91961
91962@@ -2168,6 +2225,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
91963 unsigned long uaddr = vma->vm_start;
91964 unsigned long usize = vma->vm_end - vma->vm_start;
91965
91966+ BUG_ON(vma->vm_mirror);
91967+
91968 if ((PAGE_SIZE-1) & (unsigned long)addr)
91969 return -EINVAL;
91970
91971@@ -2629,7 +2688,11 @@ static int s_show(struct seq_file *m, void *p)
91972 v->addr, v->addr + v->size, v->size);
91973
91974 if (v->caller)
91975+#ifdef CONFIG_GRKERNSEC_HIDESYM
91976+ seq_printf(m, " %pK", v->caller);
91977+#else
91978 seq_printf(m, " %pS", v->caller);
91979+#endif
91980
91981 if (v->nr_pages)
91982 seq_printf(m, " pages=%d", v->nr_pages);
91983diff --git a/mm/vmstat.c b/mm/vmstat.c
91984index f42745e..62f8346 100644
91985--- a/mm/vmstat.c
91986+++ b/mm/vmstat.c
91987@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
91988 *
91989 * vm_stat contains the global counters
91990 */
91991-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
91992+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
91993 EXPORT_SYMBOL(vm_stat);
91994
91995 #ifdef CONFIG_SMP
91996@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
91997 v = p->vm_stat_diff[i];
91998 p->vm_stat_diff[i] = 0;
91999 local_irq_restore(flags);
92000- atomic_long_add(v, &zone->vm_stat[i]);
92001+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92002 global_diff[i] += v;
92003 #ifdef CONFIG_NUMA
92004 /* 3 seconds idle till flush */
92005@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
92006
92007 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
92008 if (global_diff[i])
92009- atomic_long_add(global_diff[i], &vm_stat[i]);
92010+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
92011 }
92012
92013 /*
92014@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
92015 if (pset->vm_stat_diff[i]) {
92016 int v = pset->vm_stat_diff[i];
92017 pset->vm_stat_diff[i] = 0;
92018- atomic_long_add(v, &zone->vm_stat[i]);
92019- atomic_long_add(v, &vm_stat[i]);
92020+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
92021+ atomic_long_add_unchecked(v, &vm_stat[i]);
92022 }
92023 }
92024 #endif
92025@@ -1226,7 +1226,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
92026 return NOTIFY_OK;
92027 }
92028
92029-static struct notifier_block __cpuinitdata vmstat_notifier =
92030+static struct notifier_block vmstat_notifier =
92031 { &vmstat_cpuup_callback, NULL, 0 };
92032 #endif
92033
92034@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
92035 start_cpu_timer(cpu);
92036 #endif
92037 #ifdef CONFIG_PROC_FS
92038- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
92039- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
92040- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
92041- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
92042+ {
92043+ mode_t gr_mode = S_IRUGO;
92044+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92045+ gr_mode = S_IRUSR;
92046+#endif
92047+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
92048+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
92049+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
92050+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
92051+#else
92052+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
92053+#endif
92054+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
92055+ }
92056 #endif
92057 return 0;
92058 }
92059diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
92060index 9424f37..6aabf19 100644
92061--- a/net/8021q/vlan.c
92062+++ b/net/8021q/vlan.c
92063@@ -469,7 +469,7 @@ out:
92064 return NOTIFY_DONE;
92065 }
92066
92067-static struct notifier_block vlan_notifier_block __read_mostly = {
92068+static struct notifier_block vlan_notifier_block = {
92069 .notifier_call = vlan_device_event,
92070 };
92071
92072@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
92073 err = -EPERM;
92074 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
92075 break;
92076- if ((args.u.name_type >= 0) &&
92077- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
92078+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
92079 struct vlan_net *vn;
92080
92081 vn = net_generic(net, vlan_net_id);
92082diff --git a/net/9p/mod.c b/net/9p/mod.c
92083index 6ab36ae..6f1841b 100644
92084--- a/net/9p/mod.c
92085+++ b/net/9p/mod.c
92086@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
92087 void v9fs_register_trans(struct p9_trans_module *m)
92088 {
92089 spin_lock(&v9fs_trans_lock);
92090- list_add_tail(&m->list, &v9fs_trans_list);
92091+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
92092 spin_unlock(&v9fs_trans_lock);
92093 }
92094 EXPORT_SYMBOL(v9fs_register_trans);
92095@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
92096 void v9fs_unregister_trans(struct p9_trans_module *m)
92097 {
92098 spin_lock(&v9fs_trans_lock);
92099- list_del_init(&m->list);
92100+ pax_list_del_init((struct list_head *)&m->list);
92101 spin_unlock(&v9fs_trans_lock);
92102 }
92103 EXPORT_SYMBOL(v9fs_unregister_trans);
92104diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
92105index 02efb25..41541a9 100644
92106--- a/net/9p/trans_fd.c
92107+++ b/net/9p/trans_fd.c
92108@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
92109 oldfs = get_fs();
92110 set_fs(get_ds());
92111 /* The cast to a user pointer is valid due to the set_fs() */
92112- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
92113+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
92114 set_fs(oldfs);
92115
92116 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
92117diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
92118index 876fbe8..8bbea9f 100644
92119--- a/net/atm/atm_misc.c
92120+++ b/net/atm/atm_misc.c
92121@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
92122 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
92123 return 1;
92124 atm_return(vcc, truesize);
92125- atomic_inc(&vcc->stats->rx_drop);
92126+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92127 return 0;
92128 }
92129 EXPORT_SYMBOL(atm_charge);
92130@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
92131 }
92132 }
92133 atm_return(vcc, guess);
92134- atomic_inc(&vcc->stats->rx_drop);
92135+ atomic_inc_unchecked(&vcc->stats->rx_drop);
92136 return NULL;
92137 }
92138 EXPORT_SYMBOL(atm_alloc_charge);
92139@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
92140
92141 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92142 {
92143-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92144+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
92145 __SONET_ITEMS
92146 #undef __HANDLE_ITEM
92147 }
92148@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
92149
92150 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
92151 {
92152-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
92153+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
92154 __SONET_ITEMS
92155 #undef __HANDLE_ITEM
92156 }
92157diff --git a/net/atm/lec.h b/net/atm/lec.h
92158index 4149db1..f2ab682 100644
92159--- a/net/atm/lec.h
92160+++ b/net/atm/lec.h
92161@@ -48,7 +48,7 @@ struct lane2_ops {
92162 const u8 *tlvs, u32 sizeoftlvs);
92163 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
92164 const u8 *tlvs, u32 sizeoftlvs);
92165-};
92166+} __no_const;
92167
92168 /*
92169 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
92170diff --git a/net/atm/proc.c b/net/atm/proc.c
92171index bbb6461..cf04016 100644
92172--- a/net/atm/proc.c
92173+++ b/net/atm/proc.c
92174@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
92175 const struct k_atm_aal_stats *stats)
92176 {
92177 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
92178- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
92179- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
92180- atomic_read(&stats->rx_drop));
92181+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
92182+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
92183+ atomic_read_unchecked(&stats->rx_drop));
92184 }
92185
92186 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
92187diff --git a/net/atm/resources.c b/net/atm/resources.c
92188index 0447d5d..3cf4728 100644
92189--- a/net/atm/resources.c
92190+++ b/net/atm/resources.c
92191@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
92192 static void copy_aal_stats(struct k_atm_aal_stats *from,
92193 struct atm_aal_stats *to)
92194 {
92195-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
92196+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
92197 __AAL_STAT_ITEMS
92198 #undef __HANDLE_ITEM
92199 }
92200@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
92201 static void subtract_aal_stats(struct k_atm_aal_stats *from,
92202 struct atm_aal_stats *to)
92203 {
92204-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
92205+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
92206 __AAL_STAT_ITEMS
92207 #undef __HANDLE_ITEM
92208 }
92209diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
92210index d5744b7..506bae3 100644
92211--- a/net/ax25/sysctl_net_ax25.c
92212+++ b/net/ax25/sysctl_net_ax25.c
92213@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
92214 {
92215 char path[sizeof("net/ax25/") + IFNAMSIZ];
92216 int k;
92217- struct ctl_table *table;
92218+ ctl_table_no_const *table;
92219
92220 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
92221 if (!table)
92222diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
92223index f680ee1..97e3542 100644
92224--- a/net/batman-adv/bat_iv_ogm.c
92225+++ b/net/batman-adv/bat_iv_ogm.c
92226@@ -79,7 +79,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
92227
92228 /* randomize initial seqno to avoid collision */
92229 get_random_bytes(&random_seqno, sizeof(random_seqno));
92230- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
92231+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
92232
92233 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
92234 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
92235@@ -627,9 +627,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
92236 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
92237
92238 /* change sequence number to network order */
92239- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
92240+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
92241 batadv_ogm_packet->seqno = htonl(seqno);
92242- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
92243+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
92244
92245 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
92246 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
92247@@ -1037,7 +1037,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
92248 return;
92249
92250 /* could be changed by schedule_own_packet() */
92251- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
92252+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
92253
92254 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
92255 has_directlink_flag = 1;
92256diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
92257index de27b31..7058bfe 100644
92258--- a/net/batman-adv/bridge_loop_avoidance.c
92259+++ b/net/batman-adv/bridge_loop_avoidance.c
92260@@ -1522,6 +1522,8 @@ out:
92261 * in these cases, the skb is further handled by this function and
92262 * returns 1, otherwise it returns 0 and the caller shall further
92263 * process the skb.
92264+ *
92265+ * This call might reallocate skb data.
92266 */
92267 int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid)
92268 {
92269diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
92270index f105219..7614af3 100644
92271--- a/net/batman-adv/gateway_client.c
92272+++ b/net/batman-adv/gateway_client.c
92273@@ -508,6 +508,7 @@ out:
92274 return 0;
92275 }
92276
92277+/* this call might reallocate skb data */
92278 static bool batadv_is_type_dhcprequest(struct sk_buff *skb, int header_len)
92279 {
92280 int ret = false;
92281@@ -568,6 +569,7 @@ out:
92282 return ret;
92283 }
92284
92285+/* this call might reallocate skb data */
92286 bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
92287 {
92288 struct ethhdr *ethhdr;
92289@@ -619,6 +621,12 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
92290
92291 if (!pskb_may_pull(skb, *header_len + sizeof(*udphdr)))
92292 return false;
92293+
92294+ /* skb->data might have been reallocated by pskb_may_pull() */
92295+ ethhdr = (struct ethhdr *)skb->data;
92296+ if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
92297+ ethhdr = (struct ethhdr *)(skb->data + VLAN_HLEN);
92298+
92299 udphdr = (struct udphdr *)(skb->data + *header_len);
92300 *header_len += sizeof(*udphdr);
92301
92302@@ -634,12 +642,14 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len)
92303 return true;
92304 }
92305
92306+/* this call might reallocate skb data */
92307 bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
92308- struct sk_buff *skb, struct ethhdr *ethhdr)
92309+ struct sk_buff *skb)
92310 {
92311 struct batadv_neigh_node *neigh_curr = NULL, *neigh_old = NULL;
92312 struct batadv_orig_node *orig_dst_node = NULL;
92313 struct batadv_gw_node *curr_gw = NULL;
92314+ struct ethhdr *ethhdr;
92315 bool ret, out_of_range = false;
92316 unsigned int header_len = 0;
92317 uint8_t curr_tq_avg;
92318@@ -648,6 +658,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
92319 if (!ret)
92320 goto out;
92321
92322+ ethhdr = (struct ethhdr *)skb->data;
92323 orig_dst_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
92324 ethhdr->h_dest);
92325 if (!orig_dst_node)
92326diff --git a/net/batman-adv/gateway_client.h b/net/batman-adv/gateway_client.h
92327index 039902d..1037d75 100644
92328--- a/net/batman-adv/gateway_client.h
92329+++ b/net/batman-adv/gateway_client.h
92330@@ -34,7 +34,6 @@ void batadv_gw_node_delete(struct batadv_priv *bat_priv,
92331 void batadv_gw_node_purge(struct batadv_priv *bat_priv);
92332 int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset);
92333 bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len);
92334-bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
92335- struct sk_buff *skb, struct ethhdr *ethhdr);
92336+bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, struct sk_buff *skb);
92337
92338 #endif /* _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ */
92339diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
92340index 522243a..b48c0ef 100644
92341--- a/net/batman-adv/hard-interface.c
92342+++ b/net/batman-adv/hard-interface.c
92343@@ -401,7 +401,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
92344 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
92345 dev_add_pack(&hard_iface->batman_adv_ptype);
92346
92347- atomic_set(&hard_iface->frag_seqno, 1);
92348+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
92349 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
92350 hard_iface->net_dev->name);
92351
92352@@ -550,7 +550,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
92353 /* This can't be called via a bat_priv callback because
92354 * we have no bat_priv yet.
92355 */
92356- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
92357+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
92358 hard_iface->bat_iv.ogm_buff = NULL;
92359
92360 return hard_iface;
92361diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
92362index 819dfb0..226bacd 100644
92363--- a/net/batman-adv/soft-interface.c
92364+++ b/net/batman-adv/soft-interface.c
92365@@ -180,6 +180,9 @@ static int batadv_interface_tx(struct sk_buff *skb,
92366 if (batadv_bla_tx(bat_priv, skb, vid))
92367 goto dropped;
92368
92369+ /* skb->data might have been reallocated by batadv_bla_tx() */
92370+ ethhdr = (struct ethhdr *)skb->data;
92371+
92372 /* Register the client MAC in the transtable */
92373 if (!is_multicast_ether_addr(ethhdr->h_source))
92374 batadv_tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
92375@@ -220,6 +223,10 @@ static int batadv_interface_tx(struct sk_buff *skb,
92376 default:
92377 break;
92378 }
92379+
92380+ /* reminder: ethhdr might have become unusable from here on
92381+ * (batadv_gw_is_dhcp_target() might have reallocated skb data)
92382+ */
92383 }
92384
92385 /* ethernet packet should be broadcasted */
92386@@ -253,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
92387 primary_if->net_dev->dev_addr, ETH_ALEN);
92388
92389 /* set broadcast sequence number */
92390- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
92391+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
92392 bcast_packet->seqno = htonl(seqno);
92393
92394 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
92395@@ -266,7 +273,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
92396 /* unicast packet */
92397 } else {
92398 if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_OFF) {
92399- ret = batadv_gw_out_of_range(bat_priv, skb, ethhdr);
92400+ ret = batadv_gw_out_of_range(bat_priv, skb);
92401 if (ret)
92402 goto dropped;
92403 }
92404@@ -472,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
92405 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
92406
92407 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
92408- atomic_set(&bat_priv->bcast_seqno, 1);
92409+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
92410 atomic_set(&bat_priv->tt.vn, 0);
92411 atomic_set(&bat_priv->tt.local_changes, 0);
92412 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
92413diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
92414index aba8364..50fcbb8 100644
92415--- a/net/batman-adv/types.h
92416+++ b/net/batman-adv/types.h
92417@@ -51,7 +51,7 @@
92418 struct batadv_hard_iface_bat_iv {
92419 unsigned char *ogm_buff;
92420 int ogm_buff_len;
92421- atomic_t ogm_seqno;
92422+ atomic_unchecked_t ogm_seqno;
92423 };
92424
92425 /**
92426@@ -75,7 +75,7 @@ struct batadv_hard_iface {
92427 int16_t if_num;
92428 char if_status;
92429 struct net_device *net_dev;
92430- atomic_t frag_seqno;
92431+ atomic_unchecked_t frag_seqno;
92432 struct kobject *hardif_obj;
92433 atomic_t refcount;
92434 struct packet_type batman_adv_ptype;
92435@@ -558,7 +558,7 @@ struct batadv_priv {
92436 #ifdef CONFIG_BATMAN_ADV_DEBUG
92437 atomic_t log_level;
92438 #endif
92439- atomic_t bcast_seqno;
92440+ atomic_unchecked_t bcast_seqno;
92441 atomic_t bcast_queue_left;
92442 atomic_t batman_queue_left;
92443 char num_ifaces;
92444diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
92445index 0bb3b59..0e3052e 100644
92446--- a/net/batman-adv/unicast.c
92447+++ b/net/batman-adv/unicast.c
92448@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
92449 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
92450 frag2->flags = large_tail;
92451
92452- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
92453+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
92454 frag1->seqno = htons(seqno - 1);
92455 frag2->seqno = htons(seqno);
92456
92457@@ -326,7 +326,9 @@ static bool batadv_unicast_push_and_fill_skb(struct sk_buff *skb, int hdr_size,
92458 * @skb: the skb containing the payload to encapsulate
92459 * @orig_node: the destination node
92460 *
92461- * Returns false if the payload could not be encapsulated or true otherwise
92462+ * Returns false if the payload could not be encapsulated or true otherwise.
92463+ *
92464+ * This call might reallocate skb data.
92465 */
92466 static bool batadv_unicast_prepare_skb(struct sk_buff *skb,
92467 struct batadv_orig_node *orig_node)
92468@@ -343,7 +345,9 @@ static bool batadv_unicast_prepare_skb(struct sk_buff *skb,
92469 * @orig_node: the destination node
92470 * @packet_subtype: the batman 4addr packet subtype to use
92471 *
92472- * Returns false if the payload could not be encapsulated or true otherwise
92473+ * Returns false if the payload could not be encapsulated or true otherwise.
92474+ *
92475+ * This call might reallocate skb data.
92476 */
92477 bool batadv_unicast_4addr_prepare_skb(struct batadv_priv *bat_priv,
92478 struct sk_buff *skb,
92479@@ -401,7 +405,7 @@ int batadv_unicast_generic_send_skb(struct batadv_priv *bat_priv,
92480 struct batadv_neigh_node *neigh_node;
92481 int data_len = skb->len;
92482 int ret = NET_RX_DROP;
92483- unsigned int dev_mtu;
92484+ unsigned int dev_mtu, header_len;
92485
92486 /* get routing information */
92487 if (is_multicast_ether_addr(ethhdr->h_dest)) {
92488@@ -429,10 +433,12 @@ find_router:
92489 switch (packet_type) {
92490 case BATADV_UNICAST:
92491 batadv_unicast_prepare_skb(skb, orig_node);
92492+ header_len = sizeof(struct batadv_unicast_packet);
92493 break;
92494 case BATADV_UNICAST_4ADDR:
92495 batadv_unicast_4addr_prepare_skb(bat_priv, skb, orig_node,
92496 packet_subtype);
92497+ header_len = sizeof(struct batadv_unicast_4addr_packet);
92498 break;
92499 default:
92500 /* this function supports UNICAST and UNICAST_4ADDR only. It
92501@@ -441,6 +447,7 @@ find_router:
92502 goto out;
92503 }
92504
92505+ ethhdr = (struct ethhdr *)(skb->data + header_len);
92506 unicast_packet = (struct batadv_unicast_packet *)skb->data;
92507
92508 /* inform the destination node that we are still missing a correct route
92509diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
92510index ace5e55..a65a1c0 100644
92511--- a/net/bluetooth/hci_core.c
92512+++ b/net/bluetooth/hci_core.c
92513@@ -2211,16 +2211,16 @@ int hci_register_dev(struct hci_dev *hdev)
92514 list_add(&hdev->list, &hci_dev_list);
92515 write_unlock(&hci_dev_list_lock);
92516
92517- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
92518- WQ_MEM_RECLAIM, 1);
92519+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
92520+ WQ_MEM_RECLAIM, 1, hdev->name);
92521 if (!hdev->workqueue) {
92522 error = -ENOMEM;
92523 goto err;
92524 }
92525
92526- hdev->req_workqueue = alloc_workqueue(hdev->name,
92527+ hdev->req_workqueue = alloc_workqueue("%s",
92528 WQ_HIGHPRI | WQ_UNBOUND |
92529- WQ_MEM_RECLAIM, 1);
92530+ WQ_MEM_RECLAIM, 1, hdev->name);
92531 if (!hdev->req_workqueue) {
92532 destroy_workqueue(hdev->workqueue);
92533 error = -ENOMEM;
92534diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
92535index 9bd7d95..6c4884f 100644
92536--- a/net/bluetooth/hci_sock.c
92537+++ b/net/bluetooth/hci_sock.c
92538@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
92539 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
92540 }
92541
92542- len = min_t(unsigned int, len, sizeof(uf));
92543+ len = min((size_t)len, sizeof(uf));
92544 if (copy_from_user(&uf, optval, len)) {
92545 err = -EFAULT;
92546 break;
92547diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
92548index 68843a2..30e9342 100644
92549--- a/net/bluetooth/l2cap_core.c
92550+++ b/net/bluetooth/l2cap_core.c
92551@@ -3507,8 +3507,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
92552 break;
92553
92554 case L2CAP_CONF_RFC:
92555- if (olen == sizeof(rfc))
92556- memcpy(&rfc, (void *)val, olen);
92557+ if (olen != sizeof(rfc))
92558+ break;
92559+
92560+ memcpy(&rfc, (void *)val, olen);
92561
92562 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
92563 rfc.mode != chan->mode)
92564diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
92565index 36fed40..be2eeb2 100644
92566--- a/net/bluetooth/l2cap_sock.c
92567+++ b/net/bluetooth/l2cap_sock.c
92568@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92569 struct sock *sk = sock->sk;
92570 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
92571 struct l2cap_options opts;
92572- int len, err = 0;
92573+ int err = 0;
92574+ size_t len = optlen;
92575 u32 opt;
92576
92577 BT_DBG("sk %p", sk);
92578@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92579 opts.max_tx = chan->max_tx;
92580 opts.txwin_size = chan->tx_win;
92581
92582- len = min_t(unsigned int, sizeof(opts), optlen);
92583+ len = min(sizeof(opts), len);
92584 if (copy_from_user((char *) &opts, optval, len)) {
92585 err = -EFAULT;
92586 break;
92587@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92588 struct bt_security sec;
92589 struct bt_power pwr;
92590 struct l2cap_conn *conn;
92591- int len, err = 0;
92592+ int err = 0;
92593+ size_t len = optlen;
92594 u32 opt;
92595
92596 BT_DBG("sk %p", sk);
92597@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92598
92599 sec.level = BT_SECURITY_LOW;
92600
92601- len = min_t(unsigned int, sizeof(sec), optlen);
92602+ len = min(sizeof(sec), len);
92603 if (copy_from_user((char *) &sec, optval, len)) {
92604 err = -EFAULT;
92605 break;
92606@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92607
92608 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
92609
92610- len = min_t(unsigned int, sizeof(pwr), optlen);
92611+ len = min(sizeof(pwr), len);
92612 if (copy_from_user((char *) &pwr, optval, len)) {
92613 err = -EFAULT;
92614 break;
92615diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
92616index 30b3721..c1bd0a0 100644
92617--- a/net/bluetooth/rfcomm/sock.c
92618+++ b/net/bluetooth/rfcomm/sock.c
92619@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92620 struct sock *sk = sock->sk;
92621 struct bt_security sec;
92622 int err = 0;
92623- size_t len;
92624+ size_t len = optlen;
92625 u32 opt;
92626
92627 BT_DBG("sk %p", sk);
92628@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92629
92630 sec.level = BT_SECURITY_LOW;
92631
92632- len = min_t(unsigned int, sizeof(sec), optlen);
92633+ len = min(sizeof(sec), len);
92634 if (copy_from_user((char *) &sec, optval, len)) {
92635 err = -EFAULT;
92636 break;
92637diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
92638index b6e44ad..5b0d514 100644
92639--- a/net/bluetooth/rfcomm/tty.c
92640+++ b/net/bluetooth/rfcomm/tty.c
92641@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
92642 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
92643
92644 spin_lock_irqsave(&dev->port.lock, flags);
92645- if (dev->port.count > 0) {
92646+ if (atomic_read(&dev->port.count) > 0) {
92647 spin_unlock_irqrestore(&dev->port.lock, flags);
92648 return;
92649 }
92650@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
92651 return -ENODEV;
92652
92653 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
92654- dev->channel, dev->port.count);
92655+ dev->channel, atomic_read(&dev->port.count));
92656
92657 spin_lock_irqsave(&dev->port.lock, flags);
92658- if (++dev->port.count > 1) {
92659+ if (atomic_inc_return(&dev->port.count) > 1) {
92660 spin_unlock_irqrestore(&dev->port.lock, flags);
92661 return 0;
92662 }
92663@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
92664 return;
92665
92666 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
92667- dev->port.count);
92668+ atomic_read(&dev->port.count));
92669
92670 spin_lock_irqsave(&dev->port.lock, flags);
92671- if (!--dev->port.count) {
92672+ if (!atomic_dec_return(&dev->port.count)) {
92673 spin_unlock_irqrestore(&dev->port.lock, flags);
92674 if (dev->tty_dev->parent)
92675 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
92676diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
92677index 3d110c4..4e1b2eb 100644
92678--- a/net/bridge/netfilter/ebtables.c
92679+++ b/net/bridge/netfilter/ebtables.c
92680@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92681 tmp.valid_hooks = t->table->valid_hooks;
92682 }
92683 mutex_unlock(&ebt_mutex);
92684- if (copy_to_user(user, &tmp, *len) != 0){
92685+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
92686 BUGPRINT("c2u Didn't work\n");
92687 ret = -EFAULT;
92688 break;
92689@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92690 goto out;
92691 tmp.valid_hooks = t->valid_hooks;
92692
92693- if (copy_to_user(user, &tmp, *len) != 0) {
92694+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92695 ret = -EFAULT;
92696 break;
92697 }
92698@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92699 tmp.entries_size = t->table->entries_size;
92700 tmp.valid_hooks = t->table->valid_hooks;
92701
92702- if (copy_to_user(user, &tmp, *len) != 0) {
92703+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92704 ret = -EFAULT;
92705 break;
92706 }
92707diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
92708index 2bd4b58..0dc30a1 100644
92709--- a/net/caif/cfctrl.c
92710+++ b/net/caif/cfctrl.c
92711@@ -10,6 +10,7 @@
92712 #include <linux/spinlock.h>
92713 #include <linux/slab.h>
92714 #include <linux/pkt_sched.h>
92715+#include <linux/sched.h>
92716 #include <net/caif/caif_layer.h>
92717 #include <net/caif/cfpkt.h>
92718 #include <net/caif/cfctrl.h>
92719@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
92720 memset(&dev_info, 0, sizeof(dev_info));
92721 dev_info.id = 0xff;
92722 cfsrvl_init(&this->serv, 0, &dev_info, false);
92723- atomic_set(&this->req_seq_no, 1);
92724- atomic_set(&this->rsp_seq_no, 1);
92725+ atomic_set_unchecked(&this->req_seq_no, 1);
92726+ atomic_set_unchecked(&this->rsp_seq_no, 1);
92727 this->serv.layer.receive = cfctrl_recv;
92728 sprintf(this->serv.layer.name, "ctrl");
92729 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
92730@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
92731 struct cfctrl_request_info *req)
92732 {
92733 spin_lock_bh(&ctrl->info_list_lock);
92734- atomic_inc(&ctrl->req_seq_no);
92735- req->sequence_no = atomic_read(&ctrl->req_seq_no);
92736+ atomic_inc_unchecked(&ctrl->req_seq_no);
92737+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
92738 list_add_tail(&req->list, &ctrl->list);
92739 spin_unlock_bh(&ctrl->info_list_lock);
92740 }
92741@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
92742 if (p != first)
92743 pr_warn("Requests are not received in order\n");
92744
92745- atomic_set(&ctrl->rsp_seq_no,
92746+ atomic_set_unchecked(&ctrl->rsp_seq_no,
92747 p->sequence_no);
92748 list_del(&p->list);
92749 goto out;
92750diff --git a/net/can/af_can.c b/net/can/af_can.c
92751index c4e5085..aa9efdf 100644
92752--- a/net/can/af_can.c
92753+++ b/net/can/af_can.c
92754@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
92755 };
92756
92757 /* notifier block for netdevice event */
92758-static struct notifier_block can_netdev_notifier __read_mostly = {
92759+static struct notifier_block can_netdev_notifier = {
92760 .notifier_call = can_notifier,
92761 };
92762
92763diff --git a/net/can/gw.c b/net/can/gw.c
92764index 3ee690e..00d581b 100644
92765--- a/net/can/gw.c
92766+++ b/net/can/gw.c
92767@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
92768 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
92769
92770 static HLIST_HEAD(cgw_list);
92771-static struct notifier_block notifier;
92772
92773 static struct kmem_cache *cgw_cache __read_mostly;
92774
92775@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
92776 return err;
92777 }
92778
92779+static struct notifier_block notifier = {
92780+ .notifier_call = cgw_notifier
92781+};
92782+
92783 static __init int cgw_module_init(void)
92784 {
92785 /* sanitize given module parameter */
92786@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
92787 return -ENOMEM;
92788
92789 /* set notifier */
92790- notifier.notifier_call = cgw_notifier;
92791 register_netdevice_notifier(&notifier);
92792
92793 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
92794diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
92795index eb0a46a..5f3bae8 100644
92796--- a/net/ceph/messenger.c
92797+++ b/net/ceph/messenger.c
92798@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
92799 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
92800
92801 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
92802-static atomic_t addr_str_seq = ATOMIC_INIT(0);
92803+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
92804
92805 static struct page *zero_page; /* used in certain error cases */
92806
92807@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
92808 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
92809 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
92810
92811- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92812+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92813 s = addr_str[i];
92814
92815 switch (ss->ss_family) {
92816diff --git a/net/compat.c b/net/compat.c
92817index f0a1ba6..0541331 100644
92818--- a/net/compat.c
92819+++ b/net/compat.c
92820@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
92821 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
92822 __get_user(kmsg->msg_flags, &umsg->msg_flags))
92823 return -EFAULT;
92824- kmsg->msg_name = compat_ptr(tmp1);
92825- kmsg->msg_iov = compat_ptr(tmp2);
92826- kmsg->msg_control = compat_ptr(tmp3);
92827+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
92828+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
92829+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
92830 return 0;
92831 }
92832
92833@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92834
92835 if (kern_msg->msg_namelen) {
92836 if (mode == VERIFY_READ) {
92837- int err = move_addr_to_kernel(kern_msg->msg_name,
92838+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
92839 kern_msg->msg_namelen,
92840 kern_address);
92841 if (err < 0)
92842@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92843 kern_msg->msg_name = NULL;
92844
92845 tot_len = iov_from_user_compat_to_kern(kern_iov,
92846- (struct compat_iovec __user *)kern_msg->msg_iov,
92847+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
92848 kern_msg->msg_iovlen);
92849 if (tot_len >= 0)
92850 kern_msg->msg_iov = kern_iov;
92851@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92852
92853 #define CMSG_COMPAT_FIRSTHDR(msg) \
92854 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
92855- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
92856+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
92857 (struct compat_cmsghdr __user *)NULL)
92858
92859 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
92860 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
92861 (ucmlen) <= (unsigned long) \
92862 ((mhdr)->msg_controllen - \
92863- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
92864+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
92865
92866 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
92867 struct compat_cmsghdr __user *cmsg, int cmsg_len)
92868 {
92869 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
92870- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
92871+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
92872 msg->msg_controllen)
92873 return NULL;
92874 return (struct compat_cmsghdr __user *)ptr;
92875@@ -219,7 +219,7 @@ Efault:
92876
92877 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
92878 {
92879- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92880+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92881 struct compat_cmsghdr cmhdr;
92882 struct compat_timeval ctv;
92883 struct compat_timespec cts[3];
92884@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
92885
92886 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
92887 {
92888- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92889+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92890 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
92891 int fdnum = scm->fp->count;
92892 struct file **fp = scm->fp->fp;
92893@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
92894 return -EFAULT;
92895 old_fs = get_fs();
92896 set_fs(KERNEL_DS);
92897- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
92898+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
92899 set_fs(old_fs);
92900
92901 return err;
92902@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
92903 len = sizeof(ktime);
92904 old_fs = get_fs();
92905 set_fs(KERNEL_DS);
92906- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
92907+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
92908 set_fs(old_fs);
92909
92910 if (!err) {
92911@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92912 case MCAST_JOIN_GROUP:
92913 case MCAST_LEAVE_GROUP:
92914 {
92915- struct compat_group_req __user *gr32 = (void *)optval;
92916+ struct compat_group_req __user *gr32 = (void __user *)optval;
92917 struct group_req __user *kgr =
92918 compat_alloc_user_space(sizeof(struct group_req));
92919 u32 interface;
92920@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92921 case MCAST_BLOCK_SOURCE:
92922 case MCAST_UNBLOCK_SOURCE:
92923 {
92924- struct compat_group_source_req __user *gsr32 = (void *)optval;
92925+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
92926 struct group_source_req __user *kgsr = compat_alloc_user_space(
92927 sizeof(struct group_source_req));
92928 u32 interface;
92929@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92930 }
92931 case MCAST_MSFILTER:
92932 {
92933- struct compat_group_filter __user *gf32 = (void *)optval;
92934+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92935 struct group_filter __user *kgf;
92936 u32 interface, fmode, numsrc;
92937
92938@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
92939 char __user *optval, int __user *optlen,
92940 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
92941 {
92942- struct compat_group_filter __user *gf32 = (void *)optval;
92943+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92944 struct group_filter __user *kgf;
92945 int __user *koptlen;
92946 u32 interface, fmode, numsrc;
92947@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
92948
92949 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
92950 return -EINVAL;
92951- if (copy_from_user(a, args, nas[call]))
92952+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
92953 return -EFAULT;
92954 a0 = a[0];
92955 a1 = a[1];
92956diff --git a/net/core/datagram.c b/net/core/datagram.c
92957index b71423d..0360434 100644
92958--- a/net/core/datagram.c
92959+++ b/net/core/datagram.c
92960@@ -295,7 +295,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
92961 }
92962
92963 kfree_skb(skb);
92964- atomic_inc(&sk->sk_drops);
92965+ atomic_inc_unchecked(&sk->sk_drops);
92966 sk_mem_reclaim_partial(sk);
92967
92968 return err;
92969diff --git a/net/core/dev.c b/net/core/dev.c
92970index 7ddbb31..3902452 100644
92971--- a/net/core/dev.c
92972+++ b/net/core/dev.c
92973@@ -1649,7 +1649,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
92974 {
92975 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
92976 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
92977- atomic_long_inc(&dev->rx_dropped);
92978+ atomic_long_inc_unchecked(&dev->rx_dropped);
92979 kfree_skb(skb);
92980 return NET_RX_DROP;
92981 }
92982@@ -1658,7 +1658,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
92983 skb_orphan(skb);
92984
92985 if (unlikely(!is_skb_forwardable(dev, skb))) {
92986- atomic_long_inc(&dev->rx_dropped);
92987+ atomic_long_inc_unchecked(&dev->rx_dropped);
92988 kfree_skb(skb);
92989 return NET_RX_DROP;
92990 }
92991@@ -2404,7 +2404,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
92992
92993 struct dev_gso_cb {
92994 void (*destructor)(struct sk_buff *skb);
92995-};
92996+} __no_const;
92997
92998 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
92999
93000@@ -3139,7 +3139,7 @@ enqueue:
93001
93002 local_irq_restore(flags);
93003
93004- atomic_long_inc(&skb->dev->rx_dropped);
93005+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93006 kfree_skb(skb);
93007 return NET_RX_DROP;
93008 }
93009@@ -3211,7 +3211,7 @@ int netif_rx_ni(struct sk_buff *skb)
93010 }
93011 EXPORT_SYMBOL(netif_rx_ni);
93012
93013-static void net_tx_action(struct softirq_action *h)
93014+static void net_tx_action(void)
93015 {
93016 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93017
93018@@ -3545,7 +3545,7 @@ ncls:
93019 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
93020 } else {
93021 drop:
93022- atomic_long_inc(&skb->dev->rx_dropped);
93023+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
93024 kfree_skb(skb);
93025 /* Jamal, now you will not able to escape explaining
93026 * me how you were going to use this. :-)
93027@@ -4153,7 +4153,7 @@ void netif_napi_del(struct napi_struct *napi)
93028 }
93029 EXPORT_SYMBOL(netif_napi_del);
93030
93031-static void net_rx_action(struct softirq_action *h)
93032+static void net_rx_action(void)
93033 {
93034 struct softnet_data *sd = &__get_cpu_var(softnet_data);
93035 unsigned long time_limit = jiffies + 2;
93036@@ -5590,7 +5590,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
93037 } else {
93038 netdev_stats_to_stats64(storage, &dev->stats);
93039 }
93040- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
93041+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
93042 return storage;
93043 }
93044 EXPORT_SYMBOL(dev_get_stats);
93045diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
93046index 5b7d0e1..cb960fc 100644
93047--- a/net/core/dev_ioctl.c
93048+++ b/net/core/dev_ioctl.c
93049@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
93050 if (no_module && capable(CAP_NET_ADMIN))
93051 no_module = request_module("netdev-%s", name);
93052 if (no_module && capable(CAP_SYS_MODULE)) {
93053+#ifdef CONFIG_GRKERNSEC_MODHARDEN
93054+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
93055+#else
93056 if (!request_module("%s", name))
93057 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
93058 name);
93059+#endif
93060 }
93061 }
93062 EXPORT_SYMBOL(dev_load);
93063diff --git a/net/core/ethtool.c b/net/core/ethtool.c
93064index ce91766..3b71cdb 100644
93065--- a/net/core/ethtool.c
93066+++ b/net/core/ethtool.c
93067@@ -1319,10 +1319,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
93068 if (ret)
93069 return ret;
93070
93071- len = (tmp.len > dump.len) ? dump.len : tmp.len;
93072+ len = min(tmp.len, dump.len);
93073 if (!len)
93074 return -EFAULT;
93075
93076+ /* Don't ever let the driver think there's more space available
93077+ * than it requested with .get_dump_flag().
93078+ */
93079+ dump.len = len;
93080+
93081+ /* Always allocate enough space to hold the whole thing so that the
93082+ * driver does not need to check the length and bother with partial
93083+ * dumping.
93084+ */
93085 data = vzalloc(tmp.len);
93086 if (!data)
93087 return -ENOMEM;
93088@@ -1330,6 +1339,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
93089 if (ret)
93090 goto out;
93091
93092+ /* There are two sane possibilities:
93093+ * 1. The driver's .get_dump_data() does not touch dump.len.
93094+ * 2. Or it may set dump.len to how much it really writes, which
93095+ * should be tmp.len (or len if it can do a partial dump).
93096+ * In any case respond to userspace with the actual length of data
93097+ * it's receiving.
93098+ */
93099+ WARN_ON(dump.len != len && dump.len != tmp.len);
93100+ dump.len = len;
93101+
93102 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
93103 ret = -EFAULT;
93104 goto out;
93105diff --git a/net/core/flow.c b/net/core/flow.c
93106index 7102f16..146b4bd 100644
93107--- a/net/core/flow.c
93108+++ b/net/core/flow.c
93109@@ -61,7 +61,7 @@ struct flow_cache {
93110 struct timer_list rnd_timer;
93111 };
93112
93113-atomic_t flow_cache_genid = ATOMIC_INIT(0);
93114+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
93115 EXPORT_SYMBOL(flow_cache_genid);
93116 static struct flow_cache flow_cache_global;
93117 static struct kmem_cache *flow_cachep __read_mostly;
93118@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
93119
93120 static int flow_entry_valid(struct flow_cache_entry *fle)
93121 {
93122- if (atomic_read(&flow_cache_genid) != fle->genid)
93123+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
93124 return 0;
93125 if (fle->object && !fle->object->ops->check(fle->object))
93126 return 0;
93127@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
93128 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
93129 fcp->hash_count++;
93130 }
93131- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
93132+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
93133 flo = fle->object;
93134 if (!flo)
93135 goto ret_object;
93136@@ -279,7 +279,7 @@ nocache:
93137 }
93138 flo = resolver(net, key, family, dir, flo, ctx);
93139 if (fle) {
93140- fle->genid = atomic_read(&flow_cache_genid);
93141+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
93142 if (!IS_ERR(flo))
93143 fle->object = flo;
93144 else
93145diff --git a/net/core/iovec.c b/net/core/iovec.c
93146index de178e4..1dabd8b 100644
93147--- a/net/core/iovec.c
93148+++ b/net/core/iovec.c
93149@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93150 if (m->msg_namelen) {
93151 if (mode == VERIFY_READ) {
93152 void __user *namep;
93153- namep = (void __user __force *) m->msg_name;
93154+ namep = (void __force_user *) m->msg_name;
93155 err = move_addr_to_kernel(namep, m->msg_namelen,
93156 address);
93157 if (err < 0)
93158@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
93159 }
93160
93161 size = m->msg_iovlen * sizeof(struct iovec);
93162- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
93163+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
93164 return -EFAULT;
93165
93166 m->msg_iov = iov;
93167diff --git a/net/core/neighbour.c b/net/core/neighbour.c
93168index ce90b02..8752627 100644
93169--- a/net/core/neighbour.c
93170+++ b/net/core/neighbour.c
93171@@ -2771,7 +2771,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
93172 size_t *lenp, loff_t *ppos)
93173 {
93174 int size, ret;
93175- ctl_table tmp = *ctl;
93176+ ctl_table_no_const tmp = *ctl;
93177
93178 tmp.extra1 = &zero;
93179 tmp.extra2 = &unres_qlen_max;
93180diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
93181index 569d355..79cf2d0 100644
93182--- a/net/core/net-procfs.c
93183+++ b/net/core/net-procfs.c
93184@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
93185 else
93186 seq_printf(seq, "%04x", ntohs(pt->type));
93187
93188+#ifdef CONFIG_GRKERNSEC_HIDESYM
93189+ seq_printf(seq, " %-8s %pf\n",
93190+ pt->dev ? pt->dev->name : "", NULL);
93191+#else
93192 seq_printf(seq, " %-8s %pf\n",
93193 pt->dev ? pt->dev->name : "", pt->func);
93194+#endif
93195 }
93196
93197 return 0;
93198diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
93199index 981fed3..536af34 100644
93200--- a/net/core/net-sysfs.c
93201+++ b/net/core/net-sysfs.c
93202@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
93203 }
93204 EXPORT_SYMBOL(netdev_class_remove_file);
93205
93206-int netdev_kobject_init(void)
93207+int __init netdev_kobject_init(void)
93208 {
93209 kobj_ns_type_register(&net_ns_type_operations);
93210 return class_register(&net_class);
93211diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
93212index f9765203..9feaef8 100644
93213--- a/net/core/net_namespace.c
93214+++ b/net/core/net_namespace.c
93215@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
93216 int error;
93217 LIST_HEAD(net_exit_list);
93218
93219- list_add_tail(&ops->list, list);
93220+ pax_list_add_tail((struct list_head *)&ops->list, list);
93221 if (ops->init || (ops->id && ops->size)) {
93222 for_each_net(net) {
93223 error = ops_init(ops, net);
93224@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
93225
93226 out_undo:
93227 /* If I have an error cleanup all namespaces I initialized */
93228- list_del(&ops->list);
93229+ pax_list_del((struct list_head *)&ops->list);
93230 ops_exit_list(ops, &net_exit_list);
93231 ops_free_list(ops, &net_exit_list);
93232 return error;
93233@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
93234 struct net *net;
93235 LIST_HEAD(net_exit_list);
93236
93237- list_del(&ops->list);
93238+ pax_list_del((struct list_head *)&ops->list);
93239 for_each_net(net)
93240 list_add_tail(&net->exit_list, &net_exit_list);
93241 ops_exit_list(ops, &net_exit_list);
93242@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
93243 mutex_lock(&net_mutex);
93244 error = register_pernet_operations(&pernet_list, ops);
93245 if (!error && (first_device == &pernet_list))
93246- first_device = &ops->list;
93247+ first_device = (struct list_head *)&ops->list;
93248 mutex_unlock(&net_mutex);
93249 return error;
93250 }
93251diff --git a/net/core/netpoll.c b/net/core/netpoll.c
93252index cec074b..a53a938 100644
93253--- a/net/core/netpoll.c
93254+++ b/net/core/netpoll.c
93255@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93256 struct udphdr *udph;
93257 struct iphdr *iph;
93258 struct ethhdr *eth;
93259- static atomic_t ip_ident;
93260+ static atomic_unchecked_t ip_ident;
93261 struct ipv6hdr *ip6h;
93262
93263 udp_len = len + sizeof(*udph);
93264@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
93265 put_unaligned(0x45, (unsigned char *)iph);
93266 iph->tos = 0;
93267 put_unaligned(htons(ip_len), &(iph->tot_len));
93268- iph->id = htons(atomic_inc_return(&ip_ident));
93269+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
93270 iph->frag_off = 0;
93271 iph->ttl = 64;
93272 iph->protocol = IPPROTO_UDP;
93273diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
93274index a08bd2b..c59bd7c 100644
93275--- a/net/core/rtnetlink.c
93276+++ b/net/core/rtnetlink.c
93277@@ -58,7 +58,7 @@ struct rtnl_link {
93278 rtnl_doit_func doit;
93279 rtnl_dumpit_func dumpit;
93280 rtnl_calcit_func calcit;
93281-};
93282+} __no_const;
93283
93284 static DEFINE_MUTEX(rtnl_mutex);
93285
93286@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
93287 if (rtnl_link_ops_get(ops->kind))
93288 return -EEXIST;
93289
93290- if (!ops->dellink)
93291- ops->dellink = unregister_netdevice_queue;
93292+ if (!ops->dellink) {
93293+ pax_open_kernel();
93294+ *(void **)&ops->dellink = unregister_netdevice_queue;
93295+ pax_close_kernel();
93296+ }
93297
93298- list_add_tail(&ops->list, &link_ops);
93299+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
93300 return 0;
93301 }
93302 EXPORT_SYMBOL_GPL(__rtnl_link_register);
93303@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
93304 for_each_net(net) {
93305 __rtnl_kill_links(net, ops);
93306 }
93307- list_del(&ops->list);
93308+ pax_list_del((struct list_head *)&ops->list);
93309 }
93310 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
93311
93312@@ -2374,7 +2377,7 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
93313 struct nlattr *extfilt;
93314 u32 filter_mask = 0;
93315
93316- extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct rtgenmsg),
93317+ extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct ifinfomsg),
93318 IFLA_EXT_MASK);
93319 if (extfilt)
93320 filter_mask = nla_get_u32(extfilt);
93321diff --git a/net/core/scm.c b/net/core/scm.c
93322index 03795d0..98d6bdb 100644
93323--- a/net/core/scm.c
93324+++ b/net/core/scm.c
93325@@ -54,7 +54,7 @@ static __inline__ int scm_check_creds(struct ucred *creds)
93326 return -EINVAL;
93327
93328 if ((creds->pid == task_tgid_vnr(current) ||
93329- ns_capable(current->nsproxy->pid_ns->user_ns, CAP_SYS_ADMIN)) &&
93330+ ns_capable(task_active_pid_ns(current)->user_ns, CAP_SYS_ADMIN)) &&
93331 ((uid_eq(uid, cred->uid) || uid_eq(uid, cred->euid) ||
93332 uid_eq(uid, cred->suid)) || nsown_capable(CAP_SETUID)) &&
93333 ((gid_eq(gid, cred->gid) || gid_eq(gid, cred->egid) ||
93334@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
93335 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93336 {
93337 struct cmsghdr __user *cm
93338- = (__force struct cmsghdr __user *)msg->msg_control;
93339+ = (struct cmsghdr __force_user *)msg->msg_control;
93340 struct cmsghdr cmhdr;
93341 int cmlen = CMSG_LEN(len);
93342 int err;
93343@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
93344 err = -EFAULT;
93345 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
93346 goto out;
93347- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
93348+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
93349 goto out;
93350 cmlen = CMSG_SPACE(len);
93351 if (msg->msg_controllen < cmlen)
93352@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
93353 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93354 {
93355 struct cmsghdr __user *cm
93356- = (__force struct cmsghdr __user*)msg->msg_control;
93357+ = (struct cmsghdr __force_user *)msg->msg_control;
93358
93359 int fdmax = 0;
93360 int fdnum = scm->fp->count;
93361@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
93362 if (fdnum < fdmax)
93363 fdmax = fdnum;
93364
93365- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
93366+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
93367 i++, cmfptr++)
93368 {
93369 struct socket *sock;
93370diff --git a/net/core/skbuff.c b/net/core/skbuff.c
93371index 1c1738c..4cab7f0 100644
93372--- a/net/core/skbuff.c
93373+++ b/net/core/skbuff.c
93374@@ -3087,13 +3087,15 @@ void __init skb_init(void)
93375 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
93376 sizeof(struct sk_buff),
93377 0,
93378- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93379+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93380+ SLAB_NO_SANITIZE,
93381 NULL);
93382 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
93383 (2*sizeof(struct sk_buff)) +
93384 sizeof(atomic_t),
93385 0,
93386- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
93387+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
93388+ SLAB_NO_SANITIZE,
93389 NULL);
93390 }
93391
93392diff --git a/net/core/sock.c b/net/core/sock.c
93393index d6d024c..6ea7ab4 100644
93394--- a/net/core/sock.c
93395+++ b/net/core/sock.c
93396@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93397 struct sk_buff_head *list = &sk->sk_receive_queue;
93398
93399 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
93400- atomic_inc(&sk->sk_drops);
93401+ atomic_inc_unchecked(&sk->sk_drops);
93402 trace_sock_rcvqueue_full(sk, skb);
93403 return -ENOMEM;
93404 }
93405@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93406 return err;
93407
93408 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
93409- atomic_inc(&sk->sk_drops);
93410+ atomic_inc_unchecked(&sk->sk_drops);
93411 return -ENOBUFS;
93412 }
93413
93414@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
93415 skb_dst_force(skb);
93416
93417 spin_lock_irqsave(&list->lock, flags);
93418- skb->dropcount = atomic_read(&sk->sk_drops);
93419+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
93420 __skb_queue_tail(list, skb);
93421 spin_unlock_irqrestore(&list->lock, flags);
93422
93423@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
93424 skb->dev = NULL;
93425
93426 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
93427- atomic_inc(&sk->sk_drops);
93428+ atomic_inc_unchecked(&sk->sk_drops);
93429 goto discard_and_relse;
93430 }
93431 if (nested)
93432@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
93433 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
93434 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
93435 bh_unlock_sock(sk);
93436- atomic_inc(&sk->sk_drops);
93437+ atomic_inc_unchecked(&sk->sk_drops);
93438 goto discard_and_relse;
93439 }
93440
93441@@ -933,12 +933,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93442 struct timeval tm;
93443 } v;
93444
93445- int lv = sizeof(int);
93446- int len;
93447+ unsigned int lv = sizeof(int);
93448+ unsigned int len;
93449
93450 if (get_user(len, optlen))
93451 return -EFAULT;
93452- if (len < 0)
93453+ if (len > INT_MAX)
93454 return -EINVAL;
93455
93456 memset(&v, 0, sizeof(v));
93457@@ -1090,11 +1090,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93458
93459 case SO_PEERNAME:
93460 {
93461- char address[128];
93462+ char address[_K_SS_MAXSIZE];
93463
93464 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
93465 return -ENOTCONN;
93466- if (lv < len)
93467+ if (lv < len || sizeof address < len)
93468 return -EINVAL;
93469 if (copy_to_user(optval, address, len))
93470 return -EFAULT;
93471@@ -1161,7 +1161,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
93472
93473 if (len > lv)
93474 len = lv;
93475- if (copy_to_user(optval, &v, len))
93476+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
93477 return -EFAULT;
93478 lenout:
93479 if (put_user(len, optlen))
93480@@ -2277,7 +2277,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
93481 */
93482 smp_wmb();
93483 atomic_set(&sk->sk_refcnt, 1);
93484- atomic_set(&sk->sk_drops, 0);
93485+ atomic_set_unchecked(&sk->sk_drops, 0);
93486 }
93487 EXPORT_SYMBOL(sock_init_data);
93488
93489diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
93490index a0e9cf6..ef7f9ed 100644
93491--- a/net/core/sock_diag.c
93492+++ b/net/core/sock_diag.c
93493@@ -9,26 +9,33 @@
93494 #include <linux/inet_diag.h>
93495 #include <linux/sock_diag.h>
93496
93497-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
93498+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
93499 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
93500 static DEFINE_MUTEX(sock_diag_table_mutex);
93501
93502 int sock_diag_check_cookie(void *sk, __u32 *cookie)
93503 {
93504+#ifndef CONFIG_GRKERNSEC_HIDESYM
93505 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
93506 cookie[1] != INET_DIAG_NOCOOKIE) &&
93507 ((u32)(unsigned long)sk != cookie[0] ||
93508 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
93509 return -ESTALE;
93510 else
93511+#endif
93512 return 0;
93513 }
93514 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
93515
93516 void sock_diag_save_cookie(void *sk, __u32 *cookie)
93517 {
93518+#ifdef CONFIG_GRKERNSEC_HIDESYM
93519+ cookie[0] = 0;
93520+ cookie[1] = 0;
93521+#else
93522 cookie[0] = (u32)(unsigned long)sk;
93523 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
93524+#endif
93525 }
93526 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
93527
93528@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
93529 mutex_lock(&sock_diag_table_mutex);
93530 if (sock_diag_handlers[hndl->family])
93531 err = -EBUSY;
93532- else
93533+ else {
93534+ pax_open_kernel();
93535 sock_diag_handlers[hndl->family] = hndl;
93536+ pax_close_kernel();
93537+ }
93538 mutex_unlock(&sock_diag_table_mutex);
93539
93540 return err;
93541@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
93542
93543 mutex_lock(&sock_diag_table_mutex);
93544 BUG_ON(sock_diag_handlers[family] != hnld);
93545+ pax_open_kernel();
93546 sock_diag_handlers[family] = NULL;
93547+ pax_close_kernel();
93548 mutex_unlock(&sock_diag_table_mutex);
93549 }
93550 EXPORT_SYMBOL_GPL(sock_diag_unregister);
93551diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
93552index cfdb46a..cef55e1 100644
93553--- a/net/core/sysctl_net_core.c
93554+++ b/net/core/sysctl_net_core.c
93555@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
93556 {
93557 unsigned int orig_size, size;
93558 int ret, i;
93559- ctl_table tmp = {
93560+ ctl_table_no_const tmp = {
93561 .data = &size,
93562 .maxlen = sizeof(size),
93563 .mode = table->mode
93564@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
93565
93566 static __net_init int sysctl_core_net_init(struct net *net)
93567 {
93568- struct ctl_table *tbl;
93569+ ctl_table_no_const *tbl = NULL;
93570
93571 net->core.sysctl_somaxconn = SOMAXCONN;
93572
93573- tbl = netns_core_table;
93574 if (!net_eq(net, &init_net)) {
93575- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
93576+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
93577 if (tbl == NULL)
93578 goto err_dup;
93579
93580@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
93581 if (net->user_ns != &init_user_ns) {
93582 tbl[0].procname = NULL;
93583 }
93584- }
93585-
93586- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93587+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93588+ } else
93589+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
93590 if (net->core.sysctl_hdr == NULL)
93591 goto err_reg;
93592
93593 return 0;
93594
93595 err_reg:
93596- if (tbl != netns_core_table)
93597- kfree(tbl);
93598+ kfree(tbl);
93599 err_dup:
93600 return -ENOMEM;
93601 }
93602@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
93603 kfree(tbl);
93604 }
93605
93606-static __net_initdata struct pernet_operations sysctl_core_ops = {
93607+static __net_initconst struct pernet_operations sysctl_core_ops = {
93608 .init = sysctl_core_net_init,
93609 .exit = sysctl_core_net_exit,
93610 };
93611diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
93612index c21f200..bc4565b 100644
93613--- a/net/decnet/af_decnet.c
93614+++ b/net/decnet/af_decnet.c
93615@@ -465,6 +465,7 @@ static struct proto dn_proto = {
93616 .sysctl_rmem = sysctl_decnet_rmem,
93617 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
93618 .obj_size = sizeof(struct dn_sock),
93619+ .slab_flags = SLAB_USERCOPY,
93620 };
93621
93622 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
93623diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
93624index a55eecc..dd8428c 100644
93625--- a/net/decnet/sysctl_net_decnet.c
93626+++ b/net/decnet/sysctl_net_decnet.c
93627@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
93628
93629 if (len > *lenp) len = *lenp;
93630
93631- if (copy_to_user(buffer, addr, len))
93632+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
93633 return -EFAULT;
93634
93635 *lenp = len;
93636@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
93637
93638 if (len > *lenp) len = *lenp;
93639
93640- if (copy_to_user(buffer, devname, len))
93641+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
93642 return -EFAULT;
93643
93644 *lenp = len;
93645diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
93646index 55e1fd5..fd602b8 100644
93647--- a/net/ieee802154/6lowpan.c
93648+++ b/net/ieee802154/6lowpan.c
93649@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
93650 hc06_ptr += 3;
93651 } else {
93652 /* compress nothing */
93653- memcpy(hc06_ptr, &hdr, 4);
93654+ memcpy(hc06_ptr, hdr, 4);
93655 /* replace the top byte with new ECN | DSCP format */
93656 *hc06_ptr = tmp;
93657 hc06_ptr += 4;
93658diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
93659index d01be2a..8976537 100644
93660--- a/net/ipv4/af_inet.c
93661+++ b/net/ipv4/af_inet.c
93662@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
93663
93664 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
93665
93666- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
93667- if (!sysctl_local_reserved_ports)
93668- goto out;
93669-
93670 rc = proto_register(&tcp_prot, 1);
93671 if (rc)
93672- goto out_free_reserved_ports;
93673+ goto out;
93674
93675 rc = proto_register(&udp_prot, 1);
93676 if (rc)
93677@@ -1818,8 +1814,6 @@ out_unregister_udp_proto:
93678 proto_unregister(&udp_prot);
93679 out_unregister_tcp_proto:
93680 proto_unregister(&tcp_prot);
93681-out_free_reserved_ports:
93682- kfree(sysctl_local_reserved_ports);
93683 goto out;
93684 }
93685
93686diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
93687index 2e7f194..0fa4d6d 100644
93688--- a/net/ipv4/ah4.c
93689+++ b/net/ipv4/ah4.c
93690@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
93691 return;
93692
93693 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
93694- atomic_inc(&flow_cache_genid);
93695+ atomic_inc_unchecked(&flow_cache_genid);
93696 rt_genid_bump(net);
93697
93698 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
93699diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
93700index dfc39d4..0d4fa52 100644
93701--- a/net/ipv4/devinet.c
93702+++ b/net/ipv4/devinet.c
93703@@ -771,7 +771,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
93704 ci = nla_data(tb[IFA_CACHEINFO]);
93705 if (!ci->ifa_valid || ci->ifa_prefered > ci->ifa_valid) {
93706 err = -EINVAL;
93707- goto errout;
93708+ goto errout_free;
93709 }
93710 *pvalid_lft = ci->ifa_valid;
93711 *pprefered_lft = ci->ifa_prefered;
93712@@ -779,6 +779,8 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
93713
93714 return ifa;
93715
93716+errout_free:
93717+ inet_free_ifa(ifa);
93718 errout:
93719 return ERR_PTR(err);
93720 }
93721@@ -1529,7 +1531,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
93722 idx = 0;
93723 head = &net->dev_index_head[h];
93724 rcu_read_lock();
93725- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93726+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93727 net->dev_base_seq;
93728 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93729 if (idx < s_idx)
93730@@ -1840,7 +1842,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
93731 idx = 0;
93732 head = &net->dev_index_head[h];
93733 rcu_read_lock();
93734- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93735+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93736 net->dev_base_seq;
93737 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93738 if (idx < s_idx)
93739@@ -2065,7 +2067,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
93740 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
93741 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
93742
93743-static struct devinet_sysctl_table {
93744+static const struct devinet_sysctl_table {
93745 struct ctl_table_header *sysctl_header;
93746 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
93747 } devinet_sysctl = {
93748@@ -2183,7 +2185,7 @@ static __net_init int devinet_init_net(struct net *net)
93749 int err;
93750 struct ipv4_devconf *all, *dflt;
93751 #ifdef CONFIG_SYSCTL
93752- struct ctl_table *tbl = ctl_forward_entry;
93753+ ctl_table_no_const *tbl = NULL;
93754 struct ctl_table_header *forw_hdr;
93755 #endif
93756
93757@@ -2201,7 +2203,7 @@ static __net_init int devinet_init_net(struct net *net)
93758 goto err_alloc_dflt;
93759
93760 #ifdef CONFIG_SYSCTL
93761- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
93762+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
93763 if (tbl == NULL)
93764 goto err_alloc_ctl;
93765
93766@@ -2221,7 +2223,10 @@ static __net_init int devinet_init_net(struct net *net)
93767 goto err_reg_dflt;
93768
93769 err = -ENOMEM;
93770- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93771+ if (!net_eq(net, &init_net))
93772+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93773+ else
93774+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
93775 if (forw_hdr == NULL)
93776 goto err_reg_ctl;
93777 net->ipv4.forw_hdr = forw_hdr;
93778@@ -2237,8 +2242,7 @@ err_reg_ctl:
93779 err_reg_dflt:
93780 __devinet_sysctl_unregister(all);
93781 err_reg_all:
93782- if (tbl != ctl_forward_entry)
93783- kfree(tbl);
93784+ kfree(tbl);
93785 err_alloc_ctl:
93786 #endif
93787 if (dflt != &ipv4_devconf_dflt)
93788diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
93789index 4cfe34d..d2fac8a 100644
93790--- a/net/ipv4/esp4.c
93791+++ b/net/ipv4/esp4.c
93792@@ -477,7 +477,7 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu)
93793 }
93794
93795 return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
93796- net_adj) & ~(align - 1)) + (net_adj - 2);
93797+ net_adj) & ~(align - 1)) + net_adj - 2;
93798 }
93799
93800 static void esp4_err(struct sk_buff *skb, u32 info)
93801@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
93802 return;
93803
93804 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
93805- atomic_inc(&flow_cache_genid);
93806+ atomic_inc_unchecked(&flow_cache_genid);
93807 rt_genid_bump(net);
93808
93809 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
93810diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
93811index c7629a2..b62d139 100644
93812--- a/net/ipv4/fib_frontend.c
93813+++ b/net/ipv4/fib_frontend.c
93814@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
93815 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93816 fib_sync_up(dev);
93817 #endif
93818- atomic_inc(&net->ipv4.dev_addr_genid);
93819+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93820 rt_cache_flush(dev_net(dev));
93821 break;
93822 case NETDEV_DOWN:
93823 fib_del_ifaddr(ifa, NULL);
93824- atomic_inc(&net->ipv4.dev_addr_genid);
93825+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93826 if (ifa->ifa_dev->ifa_list == NULL) {
93827 /* Last address was deleted from this interface.
93828 * Disable IP.
93829@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
93830 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93831 fib_sync_up(dev);
93832 #endif
93833- atomic_inc(&net->ipv4.dev_addr_genid);
93834+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93835 rt_cache_flush(net);
93836 break;
93837 case NETDEV_DOWN:
93838diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
93839index 8f6cb7a..34507f9 100644
93840--- a/net/ipv4/fib_semantics.c
93841+++ b/net/ipv4/fib_semantics.c
93842@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
93843 nh->nh_saddr = inet_select_addr(nh->nh_dev,
93844 nh->nh_gw,
93845 nh->nh_parent->fib_scope);
93846- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
93847+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
93848
93849 return nh->nh_saddr;
93850 }
93851diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
93852index 49616fe..6e8a13d 100644
93853--- a/net/ipv4/fib_trie.c
93854+++ b/net/ipv4/fib_trie.c
93855@@ -71,7 +71,6 @@
93856 #include <linux/init.h>
93857 #include <linux/list.h>
93858 #include <linux/slab.h>
93859-#include <linux/prefetch.h>
93860 #include <linux/export.h>
93861 #include <net/net_namespace.h>
93862 #include <net/ip.h>
93863@@ -1761,10 +1760,8 @@ static struct leaf *leaf_walk_rcu(struct tnode *p, struct rt_trie_node *c)
93864 if (!c)
93865 continue;
93866
93867- if (IS_LEAF(c)) {
93868- prefetch(rcu_dereference_rtnl(p->child[idx]));
93869+ if (IS_LEAF(c))
93870 return (struct leaf *) c;
93871- }
93872
93873 /* Rescan start scanning in new node */
93874 p = (struct tnode *) c;
93875diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
93876index 6acb541..9ea617d 100644
93877--- a/net/ipv4/inet_connection_sock.c
93878+++ b/net/ipv4/inet_connection_sock.c
93879@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
93880 .range = { 32768, 61000 },
93881 };
93882
93883-unsigned long *sysctl_local_reserved_ports;
93884+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
93885 EXPORT_SYMBOL(sysctl_local_reserved_ports);
93886
93887 void inet_get_local_port_range(int *low, int *high)
93888diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
93889index 6af375a..c493c74 100644
93890--- a/net/ipv4/inet_hashtables.c
93891+++ b/net/ipv4/inet_hashtables.c
93892@@ -18,12 +18,15 @@
93893 #include <linux/sched.h>
93894 #include <linux/slab.h>
93895 #include <linux/wait.h>
93896+#include <linux/security.h>
93897
93898 #include <net/inet_connection_sock.h>
93899 #include <net/inet_hashtables.h>
93900 #include <net/secure_seq.h>
93901 #include <net/ip.h>
93902
93903+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
93904+
93905 /*
93906 * Allocate and initialize a new local port bind bucket.
93907 * The bindhash mutex for snum's hash chain must be held here.
93908@@ -554,6 +557,8 @@ ok:
93909 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
93910 spin_unlock(&head->lock);
93911
93912+ gr_update_task_in_ip_table(current, inet_sk(sk));
93913+
93914 if (tw) {
93915 inet_twsk_deschedule(tw, death_row);
93916 while (twrefcnt) {
93917diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
93918index 000e3d2..5472da3 100644
93919--- a/net/ipv4/inetpeer.c
93920+++ b/net/ipv4/inetpeer.c
93921@@ -503,8 +503,8 @@ relookup:
93922 if (p) {
93923 p->daddr = *daddr;
93924 atomic_set(&p->refcnt, 1);
93925- atomic_set(&p->rid, 0);
93926- atomic_set(&p->ip_id_count,
93927+ atomic_set_unchecked(&p->rid, 0);
93928+ atomic_set_unchecked(&p->ip_id_count,
93929 (daddr->family == AF_INET) ?
93930 secure_ip_id(daddr->addr.a4) :
93931 secure_ipv6_id(daddr->addr.a6));
93932diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
93933index b66910a..cfe416e 100644
93934--- a/net/ipv4/ip_fragment.c
93935+++ b/net/ipv4/ip_fragment.c
93936@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
93937 return 0;
93938
93939 start = qp->rid;
93940- end = atomic_inc_return(&peer->rid);
93941+ end = atomic_inc_return_unchecked(&peer->rid);
93942 qp->rid = end;
93943
93944 rc = qp->q.fragments && (end - start) > max;
93945@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
93946
93947 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93948 {
93949- struct ctl_table *table;
93950+ ctl_table_no_const *table = NULL;
93951 struct ctl_table_header *hdr;
93952
93953- table = ip4_frags_ns_ctl_table;
93954 if (!net_eq(net, &init_net)) {
93955- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93956+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93957 if (table == NULL)
93958 goto err_alloc;
93959
93960@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93961 /* Don't export sysctls to unprivileged users */
93962 if (net->user_ns != &init_user_ns)
93963 table[0].procname = NULL;
93964- }
93965+ hdr = register_net_sysctl(net, "net/ipv4", table);
93966+ } else
93967+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
93968
93969- hdr = register_net_sysctl(net, "net/ipv4", table);
93970 if (hdr == NULL)
93971 goto err_reg;
93972
93973@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93974 return 0;
93975
93976 err_reg:
93977- if (!net_eq(net, &init_net))
93978- kfree(table);
93979+ kfree(table);
93980 err_alloc:
93981 return -ENOMEM;
93982 }
93983diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
93984index 855004f..9644112 100644
93985--- a/net/ipv4/ip_gre.c
93986+++ b/net/ipv4/ip_gre.c
93987@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
93988 module_param(log_ecn_error, bool, 0644);
93989 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
93990
93991-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
93992+static struct rtnl_link_ops ipgre_link_ops;
93993 static int ipgre_tunnel_init(struct net_device *dev);
93994
93995 static int ipgre_net_id __read_mostly;
93996@@ -572,7 +572,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev,
93997 if (daddr)
93998 memcpy(&iph->daddr, daddr, 4);
93999 if (iph->daddr)
94000- return t->hlen;
94001+ return t->hlen + sizeof(*iph);
94002
94003 return -(t->hlen + sizeof(*iph));
94004 }
94005@@ -919,7 +919,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
94006 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
94007 };
94008
94009-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94010+static struct rtnl_link_ops ipgre_link_ops = {
94011 .kind = "gre",
94012 .maxtype = IFLA_GRE_MAX,
94013 .policy = ipgre_policy,
94014@@ -933,7 +933,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
94015 .fill_info = ipgre_fill_info,
94016 };
94017
94018-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
94019+static struct rtnl_link_ops ipgre_tap_ops = {
94020 .kind = "gretap",
94021 .maxtype = IFLA_GRE_MAX,
94022 .policy = ipgre_policy,
94023diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
94024index d9c4f11..02b82dbc 100644
94025--- a/net/ipv4/ip_sockglue.c
94026+++ b/net/ipv4/ip_sockglue.c
94027@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94028 len = min_t(unsigned int, len, opt->optlen);
94029 if (put_user(len, optlen))
94030 return -EFAULT;
94031- if (copy_to_user(optval, opt->__data, len))
94032+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
94033+ copy_to_user(optval, opt->__data, len))
94034 return -EFAULT;
94035 return 0;
94036 }
94037@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
94038 if (sk->sk_type != SOCK_STREAM)
94039 return -ENOPROTOOPT;
94040
94041- msg.msg_control = optval;
94042+ msg.msg_control = (void __force_kernel *)optval;
94043 msg.msg_controllen = len;
94044 msg.msg_flags = flags;
94045
94046diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
94047index 17cc0ff..63856c4 100644
94048--- a/net/ipv4/ip_vti.c
94049+++ b/net/ipv4/ip_vti.c
94050@@ -47,7 +47,7 @@
94051 #define HASH_SIZE 16
94052 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
94053
94054-static struct rtnl_link_ops vti_link_ops __read_mostly;
94055+static struct rtnl_link_ops vti_link_ops;
94056
94057 static int vti_net_id __read_mostly;
94058 struct vti_net {
94059@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
94060 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
94061 };
94062
94063-static struct rtnl_link_ops vti_link_ops __read_mostly = {
94064+static struct rtnl_link_ops vti_link_ops = {
94065 .kind = "vti",
94066 .maxtype = IFLA_VTI_MAX,
94067 .policy = vti_policy,
94068diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
94069index 59cb8c7..a72160c 100644
94070--- a/net/ipv4/ipcomp.c
94071+++ b/net/ipv4/ipcomp.c
94072@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
94073 return;
94074
94075 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
94076- atomic_inc(&flow_cache_genid);
94077+ atomic_inc_unchecked(&flow_cache_genid);
94078 rt_genid_bump(net);
94079
94080 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
94081diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
94082index efa1138..20dbba0 100644
94083--- a/net/ipv4/ipconfig.c
94084+++ b/net/ipv4/ipconfig.c
94085@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
94086
94087 mm_segment_t oldfs = get_fs();
94088 set_fs(get_ds());
94089- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94090+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94091 set_fs(oldfs);
94092 return res;
94093 }
94094@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
94095
94096 mm_segment_t oldfs = get_fs();
94097 set_fs(get_ds());
94098- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
94099+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
94100 set_fs(oldfs);
94101 return res;
94102 }
94103@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
94104
94105 mm_segment_t oldfs = get_fs();
94106 set_fs(get_ds());
94107- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
94108+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
94109 set_fs(oldfs);
94110 return res;
94111 }
94112diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
94113index 7cfc456..e726868 100644
94114--- a/net/ipv4/ipip.c
94115+++ b/net/ipv4/ipip.c
94116@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
94117 static int ipip_net_id __read_mostly;
94118
94119 static int ipip_tunnel_init(struct net_device *dev);
94120-static struct rtnl_link_ops ipip_link_ops __read_mostly;
94121+static struct rtnl_link_ops ipip_link_ops;
94122
94123 static int ipip_err(struct sk_buff *skb, u32 info)
94124 {
94125@@ -406,7 +406,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
94126 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
94127 };
94128
94129-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
94130+static struct rtnl_link_ops ipip_link_ops = {
94131 .kind = "ipip",
94132 .maxtype = IFLA_IPTUN_MAX,
94133 .policy = ipip_policy,
94134diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
94135index 85a4f21..1beb1f5 100644
94136--- a/net/ipv4/netfilter/arp_tables.c
94137+++ b/net/ipv4/netfilter/arp_tables.c
94138@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
94139 #endif
94140
94141 static int get_info(struct net *net, void __user *user,
94142- const int *len, int compat)
94143+ int len, int compat)
94144 {
94145 char name[XT_TABLE_MAXNAMELEN];
94146 struct xt_table *t;
94147 int ret;
94148
94149- if (*len != sizeof(struct arpt_getinfo)) {
94150- duprintf("length %u != %Zu\n", *len,
94151+ if (len != sizeof(struct arpt_getinfo)) {
94152+ duprintf("length %u != %Zu\n", len,
94153 sizeof(struct arpt_getinfo));
94154 return -EINVAL;
94155 }
94156@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
94157 info.size = private->size;
94158 strcpy(info.name, name);
94159
94160- if (copy_to_user(user, &info, *len) != 0)
94161+ if (copy_to_user(user, &info, len) != 0)
94162 ret = -EFAULT;
94163 else
94164 ret = 0;
94165@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
94166
94167 switch (cmd) {
94168 case ARPT_SO_GET_INFO:
94169- ret = get_info(sock_net(sk), user, len, 1);
94170+ ret = get_info(sock_net(sk), user, *len, 1);
94171 break;
94172 case ARPT_SO_GET_ENTRIES:
94173 ret = compat_get_entries(sock_net(sk), user, len);
94174@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
94175
94176 switch (cmd) {
94177 case ARPT_SO_GET_INFO:
94178- ret = get_info(sock_net(sk), user, len, 0);
94179+ ret = get_info(sock_net(sk), user, *len, 0);
94180 break;
94181
94182 case ARPT_SO_GET_ENTRIES:
94183diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
94184index d23118d..6ad7277 100644
94185--- a/net/ipv4/netfilter/ip_tables.c
94186+++ b/net/ipv4/netfilter/ip_tables.c
94187@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
94188 #endif
94189
94190 static int get_info(struct net *net, void __user *user,
94191- const int *len, int compat)
94192+ int len, int compat)
94193 {
94194 char name[XT_TABLE_MAXNAMELEN];
94195 struct xt_table *t;
94196 int ret;
94197
94198- if (*len != sizeof(struct ipt_getinfo)) {
94199- duprintf("length %u != %zu\n", *len,
94200+ if (len != sizeof(struct ipt_getinfo)) {
94201+ duprintf("length %u != %zu\n", len,
94202 sizeof(struct ipt_getinfo));
94203 return -EINVAL;
94204 }
94205@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
94206 info.size = private->size;
94207 strcpy(info.name, name);
94208
94209- if (copy_to_user(user, &info, *len) != 0)
94210+ if (copy_to_user(user, &info, len) != 0)
94211 ret = -EFAULT;
94212 else
94213 ret = 0;
94214@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94215
94216 switch (cmd) {
94217 case IPT_SO_GET_INFO:
94218- ret = get_info(sock_net(sk), user, len, 1);
94219+ ret = get_info(sock_net(sk), user, *len, 1);
94220 break;
94221 case IPT_SO_GET_ENTRIES:
94222 ret = compat_get_entries(sock_net(sk), user, len);
94223@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94224
94225 switch (cmd) {
94226 case IPT_SO_GET_INFO:
94227- ret = get_info(sock_net(sk), user, len, 0);
94228+ ret = get_info(sock_net(sk), user, *len, 0);
94229 break;
94230
94231 case IPT_SO_GET_ENTRIES:
94232diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
94233index 7d93d62..cbbf2a3 100644
94234--- a/net/ipv4/ping.c
94235+++ b/net/ipv4/ping.c
94236@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
94237 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94238 0, sock_i_ino(sp),
94239 atomic_read(&sp->sk_refcnt), sp,
94240- atomic_read(&sp->sk_drops), len);
94241+ atomic_read_unchecked(&sp->sk_drops), len);
94242 }
94243
94244 static int ping_seq_show(struct seq_file *seq, void *v)
94245diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
94246index dd44e0a..06dcca4 100644
94247--- a/net/ipv4/raw.c
94248+++ b/net/ipv4/raw.c
94249@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
94250 int raw_rcv(struct sock *sk, struct sk_buff *skb)
94251 {
94252 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
94253- atomic_inc(&sk->sk_drops);
94254+ atomic_inc_unchecked(&sk->sk_drops);
94255 kfree_skb(skb);
94256 return NET_RX_DROP;
94257 }
94258@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
94259
94260 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
94261 {
94262+ struct icmp_filter filter;
94263+
94264 if (optlen > sizeof(struct icmp_filter))
94265 optlen = sizeof(struct icmp_filter);
94266- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
94267+ if (copy_from_user(&filter, optval, optlen))
94268 return -EFAULT;
94269+ raw_sk(sk)->filter = filter;
94270 return 0;
94271 }
94272
94273 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
94274 {
94275 int len, ret = -EFAULT;
94276+ struct icmp_filter filter;
94277
94278 if (get_user(len, optlen))
94279 goto out;
94280@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
94281 if (len > sizeof(struct icmp_filter))
94282 len = sizeof(struct icmp_filter);
94283 ret = -EFAULT;
94284- if (put_user(len, optlen) ||
94285- copy_to_user(optval, &raw_sk(sk)->filter, len))
94286+ filter = raw_sk(sk)->filter;
94287+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
94288 goto out;
94289 ret = 0;
94290 out: return ret;
94291@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
94292 0, 0L, 0,
94293 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
94294 0, sock_i_ino(sp),
94295- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
94296+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
94297 }
94298
94299 static int raw_seq_show(struct seq_file *seq, void *v)
94300diff --git a/net/ipv4/route.c b/net/ipv4/route.c
94301index d35bbf0..faa3ab8 100644
94302--- a/net/ipv4/route.c
94303+++ b/net/ipv4/route.c
94304@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
94305 .maxlen = sizeof(int),
94306 .mode = 0200,
94307 .proc_handler = ipv4_sysctl_rtcache_flush,
94308+ .extra1 = &init_net,
94309 },
94310 { },
94311 };
94312
94313 static __net_init int sysctl_route_net_init(struct net *net)
94314 {
94315- struct ctl_table *tbl;
94316+ ctl_table_no_const *tbl = NULL;
94317
94318- tbl = ipv4_route_flush_table;
94319 if (!net_eq(net, &init_net)) {
94320- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94321+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
94322 if (tbl == NULL)
94323 goto err_dup;
94324
94325 /* Don't export sysctls to unprivileged users */
94326 if (net->user_ns != &init_user_ns)
94327 tbl[0].procname = NULL;
94328- }
94329- tbl[0].extra1 = net;
94330+ tbl[0].extra1 = net;
94331+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
94332+ } else
94333+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
94334
94335- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
94336 if (net->ipv4.route_hdr == NULL)
94337 goto err_reg;
94338 return 0;
94339
94340 err_reg:
94341- if (tbl != ipv4_route_flush_table)
94342- kfree(tbl);
94343+ kfree(tbl);
94344 err_dup:
94345 return -ENOMEM;
94346 }
94347@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
94348
94349 static __net_init int rt_genid_init(struct net *net)
94350 {
94351- atomic_set(&net->rt_genid, 0);
94352+ atomic_set_unchecked(&net->rt_genid, 0);
94353 get_random_bytes(&net->ipv4.dev_addr_genid,
94354 sizeof(net->ipv4.dev_addr_genid));
94355 return 0;
94356diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
94357index 3f25e75..3ae0f4d 100644
94358--- a/net/ipv4/sysctl_net_ipv4.c
94359+++ b/net/ipv4/sysctl_net_ipv4.c
94360@@ -57,7 +57,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
94361 {
94362 int ret;
94363 int range[2];
94364- ctl_table tmp = {
94365+ ctl_table_no_const tmp = {
94366 .data = &range,
94367 .maxlen = sizeof(range),
94368 .mode = table->mode,
94369@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
94370 int ret;
94371 gid_t urange[2];
94372 kgid_t low, high;
94373- ctl_table tmp = {
94374+ ctl_table_no_const tmp = {
94375 .data = &urange,
94376 .maxlen = sizeof(urange),
94377 .mode = table->mode,
94378@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
94379 void __user *buffer, size_t *lenp, loff_t *ppos)
94380 {
94381 char val[TCP_CA_NAME_MAX];
94382- ctl_table tbl = {
94383+ ctl_table_no_const tbl = {
94384 .data = val,
94385 .maxlen = TCP_CA_NAME_MAX,
94386 };
94387@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
94388 void __user *buffer, size_t *lenp,
94389 loff_t *ppos)
94390 {
94391- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
94392+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
94393 int ret;
94394
94395 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94396@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
94397 void __user *buffer, size_t *lenp,
94398 loff_t *ppos)
94399 {
94400- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
94401+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
94402 int ret;
94403
94404 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94405@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
94406 struct mem_cgroup *memcg;
94407 #endif
94408
94409- ctl_table tmp = {
94410+ ctl_table_no_const tmp = {
94411 .data = &vec,
94412 .maxlen = sizeof(vec),
94413 .mode = ctl->mode,
94414 };
94415
94416 if (!write) {
94417- ctl->data = &net->ipv4.sysctl_tcp_mem;
94418- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
94419+ ctl_table_no_const tcp_mem = *ctl;
94420+
94421+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
94422+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
94423 }
94424
94425 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
94426@@ -238,7 +240,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
94427 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
94428 size_t *lenp, loff_t *ppos)
94429 {
94430- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94431+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
94432 struct tcp_fastopen_context *ctxt;
94433 int ret;
94434 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
94435@@ -481,7 +483,7 @@ static struct ctl_table ipv4_table[] = {
94436 },
94437 {
94438 .procname = "ip_local_reserved_ports",
94439- .data = NULL, /* initialized in sysctl_ipv4_init */
94440+ .data = sysctl_local_reserved_ports,
94441 .maxlen = 65536,
94442 .mode = 0644,
94443 .proc_handler = proc_do_large_bitmap,
94444@@ -846,11 +848,10 @@ static struct ctl_table ipv4_net_table[] = {
94445
94446 static __net_init int ipv4_sysctl_init_net(struct net *net)
94447 {
94448- struct ctl_table *table;
94449+ ctl_table_no_const *table = NULL;
94450
94451- table = ipv4_net_table;
94452 if (!net_eq(net, &init_net)) {
94453- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
94454+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
94455 if (table == NULL)
94456 goto err_alloc;
94457
94458@@ -885,15 +886,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
94459
94460 tcp_init_mem(net);
94461
94462- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94463+ if (!net_eq(net, &init_net))
94464+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
94465+ else
94466+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
94467 if (net->ipv4.ipv4_hdr == NULL)
94468 goto err_reg;
94469
94470 return 0;
94471
94472 err_reg:
94473- if (!net_eq(net, &init_net))
94474- kfree(table);
94475+ kfree(table);
94476 err_alloc:
94477 return -ENOMEM;
94478 }
94479@@ -915,16 +918,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
94480 static __init int sysctl_ipv4_init(void)
94481 {
94482 struct ctl_table_header *hdr;
94483- struct ctl_table *i;
94484-
94485- for (i = ipv4_table; i->procname; i++) {
94486- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
94487- i->data = sysctl_local_reserved_ports;
94488- break;
94489- }
94490- }
94491- if (!i->procname)
94492- return -EINVAL;
94493
94494 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
94495 if (hdr == NULL)
94496diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
94497index 9c62257..651cc27 100644
94498--- a/net/ipv4/tcp_input.c
94499+++ b/net/ipv4/tcp_input.c
94500@@ -4436,7 +4436,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
94501 * simplifies code)
94502 */
94503 static void
94504-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94505+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94506 struct sk_buff *head, struct sk_buff *tail,
94507 u32 start, u32 end)
94508 {
94509@@ -5522,6 +5522,7 @@ discard:
94510 tcp_paws_reject(&tp->rx_opt, 0))
94511 goto discard_and_undo;
94512
94513+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
94514 if (th->syn) {
94515 /* We see SYN without ACK. It is attempt of
94516 * simultaneous connect with crossed SYNs.
94517@@ -5572,6 +5573,7 @@ discard:
94518 goto discard;
94519 #endif
94520 }
94521+#endif
94522 /* "fifth, if neither of the SYN or RST bits is set then
94523 * drop the segment and return."
94524 */
94525@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
94526 goto discard;
94527
94528 if (th->syn) {
94529- if (th->fin)
94530+ if (th->fin || th->urg || th->psh)
94531 goto discard;
94532 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
94533 return 1;
94534diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
94535index 7999fc5..c812f42 100644
94536--- a/net/ipv4/tcp_ipv4.c
94537+++ b/net/ipv4/tcp_ipv4.c
94538@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
94539 EXPORT_SYMBOL(sysctl_tcp_low_latency);
94540
94541
94542+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94543+extern int grsec_enable_blackhole;
94544+#endif
94545+
94546 #ifdef CONFIG_TCP_MD5SIG
94547 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
94548 __be32 daddr, __be32 saddr, const struct tcphdr *th);
94549@@ -1855,6 +1859,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
94550 return 0;
94551
94552 reset:
94553+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94554+ if (!grsec_enable_blackhole)
94555+#endif
94556 tcp_v4_send_reset(rsk, skb);
94557 discard:
94558 kfree_skb(skb);
94559@@ -2000,12 +2007,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
94560 TCP_SKB_CB(skb)->sacked = 0;
94561
94562 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
94563- if (!sk)
94564+ if (!sk) {
94565+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94566+ ret = 1;
94567+#endif
94568 goto no_tcp_socket;
94569-
94570+ }
94571 process:
94572- if (sk->sk_state == TCP_TIME_WAIT)
94573+ if (sk->sk_state == TCP_TIME_WAIT) {
94574+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94575+ ret = 2;
94576+#endif
94577 goto do_time_wait;
94578+ }
94579
94580 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
94581 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
94582@@ -2058,6 +2072,10 @@ csum_error:
94583 bad_packet:
94584 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
94585 } else {
94586+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94587+ if (!grsec_enable_blackhole || (ret == 1 &&
94588+ (skb->dev->flags & IFF_LOOPBACK)))
94589+#endif
94590 tcp_v4_send_reset(NULL, skb);
94591 }
94592
94593diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
94594index 0f01788..d52a859 100644
94595--- a/net/ipv4/tcp_minisocks.c
94596+++ b/net/ipv4/tcp_minisocks.c
94597@@ -27,6 +27,10 @@
94598 #include <net/inet_common.h>
94599 #include <net/xfrm.h>
94600
94601+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94602+extern int grsec_enable_blackhole;
94603+#endif
94604+
94605 int sysctl_tcp_syncookies __read_mostly = 1;
94606 EXPORT_SYMBOL(sysctl_tcp_syncookies);
94607
94608@@ -717,7 +721,10 @@ embryonic_reset:
94609 * avoid becoming vulnerable to outside attack aiming at
94610 * resetting legit local connections.
94611 */
94612- req->rsk_ops->send_reset(sk, skb);
94613+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94614+ if (!grsec_enable_blackhole)
94615+#endif
94616+ req->rsk_ops->send_reset(sk, skb);
94617 } else if (fastopen) { /* received a valid RST pkt */
94618 reqsk_fastopen_remove(sk, req, true);
94619 tcp_reset(sk);
94620diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
94621index d4943f6..e7a74a5 100644
94622--- a/net/ipv4/tcp_probe.c
94623+++ b/net/ipv4/tcp_probe.c
94624@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
94625 if (cnt + width >= len)
94626 break;
94627
94628- if (copy_to_user(buf + cnt, tbuf, width))
94629+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
94630 return -EFAULT;
94631 cnt += width;
94632 }
94633diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
94634index 4b85e6f..22f9ac9 100644
94635--- a/net/ipv4/tcp_timer.c
94636+++ b/net/ipv4/tcp_timer.c
94637@@ -22,6 +22,10 @@
94638 #include <linux/gfp.h>
94639 #include <net/tcp.h>
94640
94641+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94642+extern int grsec_lastack_retries;
94643+#endif
94644+
94645 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
94646 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
94647 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
94648@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
94649 }
94650 }
94651
94652+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94653+ if ((sk->sk_state == TCP_LAST_ACK) &&
94654+ (grsec_lastack_retries > 0) &&
94655+ (grsec_lastack_retries < retry_until))
94656+ retry_until = grsec_lastack_retries;
94657+#endif
94658+
94659 if (retransmits_timed_out(sk, retry_until,
94660 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
94661 /* Has it gone just too far? */
94662diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
94663index 93b731d..5a2dd92 100644
94664--- a/net/ipv4/udp.c
94665+++ b/net/ipv4/udp.c
94666@@ -87,6 +87,7 @@
94667 #include <linux/types.h>
94668 #include <linux/fcntl.h>
94669 #include <linux/module.h>
94670+#include <linux/security.h>
94671 #include <linux/socket.h>
94672 #include <linux/sockios.h>
94673 #include <linux/igmp.h>
94674@@ -111,6 +112,10 @@
94675 #include <trace/events/skb.h>
94676 #include "udp_impl.h"
94677
94678+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94679+extern int grsec_enable_blackhole;
94680+#endif
94681+
94682 struct udp_table udp_table __read_mostly;
94683 EXPORT_SYMBOL(udp_table);
94684
94685@@ -594,6 +599,9 @@ found:
94686 return s;
94687 }
94688
94689+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
94690+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
94691+
94692 /*
94693 * This routine is called by the ICMP module when it gets some
94694 * sort of error condition. If err < 0 then the socket should
94695@@ -890,9 +898,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94696 dport = usin->sin_port;
94697 if (dport == 0)
94698 return -EINVAL;
94699+
94700+ err = gr_search_udp_sendmsg(sk, usin);
94701+ if (err)
94702+ return err;
94703 } else {
94704 if (sk->sk_state != TCP_ESTABLISHED)
94705 return -EDESTADDRREQ;
94706+
94707+ err = gr_search_udp_sendmsg(sk, NULL);
94708+ if (err)
94709+ return err;
94710+
94711 daddr = inet->inet_daddr;
94712 dport = inet->inet_dport;
94713 /* Open fast path for connected socket.
94714@@ -1136,7 +1153,7 @@ static unsigned int first_packet_length(struct sock *sk)
94715 IS_UDPLITE(sk));
94716 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94717 IS_UDPLITE(sk));
94718- atomic_inc(&sk->sk_drops);
94719+ atomic_inc_unchecked(&sk->sk_drops);
94720 __skb_unlink(skb, rcvq);
94721 __skb_queue_tail(&list_kill, skb);
94722 }
94723@@ -1222,6 +1239,10 @@ try_again:
94724 if (!skb)
94725 goto out;
94726
94727+ err = gr_search_udp_recvmsg(sk, skb);
94728+ if (err)
94729+ goto out_free;
94730+
94731 ulen = skb->len - sizeof(struct udphdr);
94732 copied = len;
94733 if (copied > ulen)
94734@@ -1255,7 +1276,7 @@ try_again:
94735 if (unlikely(err)) {
94736 trace_kfree_skb(skb, udp_recvmsg);
94737 if (!peeked) {
94738- atomic_inc(&sk->sk_drops);
94739+ atomic_inc_unchecked(&sk->sk_drops);
94740 UDP_INC_STATS_USER(sock_net(sk),
94741 UDP_MIB_INERRORS, is_udplite);
94742 }
94743@@ -1542,7 +1563,7 @@ csum_error:
94744 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
94745 drop:
94746 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
94747- atomic_inc(&sk->sk_drops);
94748+ atomic_inc_unchecked(&sk->sk_drops);
94749 kfree_skb(skb);
94750 return -1;
94751 }
94752@@ -1561,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
94753 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
94754
94755 if (!skb1) {
94756- atomic_inc(&sk->sk_drops);
94757+ atomic_inc_unchecked(&sk->sk_drops);
94758 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
94759 IS_UDPLITE(sk));
94760 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94761@@ -1730,6 +1751,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
94762 goto csum_error;
94763
94764 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
94765+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94766+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
94767+#endif
94768 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
94769
94770 /*
94771@@ -2160,7 +2184,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
94772 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94773 0, sock_i_ino(sp),
94774 atomic_read(&sp->sk_refcnt), sp,
94775- atomic_read(&sp->sk_drops), len);
94776+ atomic_read_unchecked(&sp->sk_drops), len);
94777 }
94778
94779 int udp4_seq_show(struct seq_file *seq, void *v)
94780diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
94781index 9a459be..086b866 100644
94782--- a/net/ipv4/xfrm4_policy.c
94783+++ b/net/ipv4/xfrm4_policy.c
94784@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
94785
94786 static int __net_init xfrm4_net_init(struct net *net)
94787 {
94788- struct ctl_table *table;
94789+ ctl_table_no_const *table = NULL;
94790 struct ctl_table_header *hdr;
94791
94792- table = xfrm4_policy_table;
94793 if (!net_eq(net, &init_net)) {
94794- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94795+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94796 if (!table)
94797 goto err_alloc;
94798
94799 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
94800- }
94801-
94802- hdr = register_net_sysctl(net, "net/ipv4", table);
94803+ hdr = register_net_sysctl(net, "net/ipv4", table);
94804+ } else
94805+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
94806 if (!hdr)
94807 goto err_reg;
94808
94809@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
94810 return 0;
94811
94812 err_reg:
94813- if (!net_eq(net, &init_net))
94814- kfree(table);
94815+ kfree(table);
94816 err_alloc:
94817 return -ENOMEM;
94818 }
94819diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
94820index fb8c94c..80a31d8 100644
94821--- a/net/ipv6/addrconf.c
94822+++ b/net/ipv6/addrconf.c
94823@@ -621,7 +621,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
94824 idx = 0;
94825 head = &net->dev_index_head[h];
94826 rcu_read_lock();
94827- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
94828+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
94829 net->dev_base_seq;
94830 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94831 if (idx < s_idx)
94832@@ -1124,12 +1124,10 @@ retry:
94833 if (ifp->flags & IFA_F_OPTIMISTIC)
94834 addr_flags |= IFA_F_OPTIMISTIC;
94835
94836- ift = !max_addresses ||
94837- ipv6_count_addresses(idev) < max_addresses ?
94838- ipv6_add_addr(idev, &addr, tmp_plen,
94839- ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK,
94840- addr_flags) : NULL;
94841- if (IS_ERR_OR_NULL(ift)) {
94842+ ift = ipv6_add_addr(idev, &addr, tmp_plen,
94843+ ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK,
94844+ addr_flags);
94845+ if (IS_ERR(ift)) {
94846 in6_ifa_put(ifp);
94847 in6_dev_put(idev);
94848 pr_info("%s: retry temporary address regeneration\n", __func__);
94849@@ -2380,7 +2378,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
94850 p.iph.ihl = 5;
94851 p.iph.protocol = IPPROTO_IPV6;
94852 p.iph.ttl = 64;
94853- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
94854+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
94855
94856 if (ops->ndo_do_ioctl) {
94857 mm_segment_t oldfs = get_fs();
94858@@ -4002,7 +4000,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
94859 s_ip_idx = ip_idx = cb->args[2];
94860
94861 rcu_read_lock();
94862- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94863+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94864 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
94865 idx = 0;
94866 head = &net->dev_index_head[h];
94867@@ -4587,7 +4585,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
94868 dst_free(&ifp->rt->dst);
94869 break;
94870 }
94871- atomic_inc(&net->ipv6.dev_addr_genid);
94872+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
94873 }
94874
94875 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
94876@@ -4607,7 +4605,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
94877 int *valp = ctl->data;
94878 int val = *valp;
94879 loff_t pos = *ppos;
94880- ctl_table lctl;
94881+ ctl_table_no_const lctl;
94882 int ret;
94883
94884 /*
94885@@ -4689,7 +4687,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
94886 int *valp = ctl->data;
94887 int val = *valp;
94888 loff_t pos = *ppos;
94889- ctl_table lctl;
94890+ ctl_table_no_const lctl;
94891 int ret;
94892
94893 /*
94894diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
94895index 40ffd72..aeac0dc 100644
94896--- a/net/ipv6/esp6.c
94897+++ b/net/ipv6/esp6.c
94898@@ -425,7 +425,7 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu)
94899 net_adj = 0;
94900
94901 return ((mtu - x->props.header_len - crypto_aead_authsize(esp->aead) -
94902- net_adj) & ~(align - 1)) + (net_adj - 2);
94903+ net_adj) & ~(align - 1)) + net_adj - 2;
94904 }
94905
94906 static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
94907diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
94908index b4ff0a4..db9b764 100644
94909--- a/net/ipv6/icmp.c
94910+++ b/net/ipv6/icmp.c
94911@@ -980,7 +980,7 @@ ctl_table ipv6_icmp_table_template[] = {
94912
94913 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
94914 {
94915- struct ctl_table *table;
94916+ ctl_table_no_const *table;
94917
94918 table = kmemdup(ipv6_icmp_table_template,
94919 sizeof(ipv6_icmp_table_template),
94920diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
94921index ecd6073..58162ae 100644
94922--- a/net/ipv6/ip6_gre.c
94923+++ b/net/ipv6/ip6_gre.c
94924@@ -74,7 +74,7 @@ struct ip6gre_net {
94925 struct net_device *fb_tunnel_dev;
94926 };
94927
94928-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
94929+static struct rtnl_link_ops ip6gre_link_ops;
94930 static int ip6gre_tunnel_init(struct net_device *dev);
94931 static void ip6gre_tunnel_setup(struct net_device *dev);
94932 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
94933@@ -1283,7 +1283,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
94934 }
94935
94936
94937-static struct inet6_protocol ip6gre_protocol __read_mostly = {
94938+static struct inet6_protocol ip6gre_protocol = {
94939 .handler = ip6gre_rcv,
94940 .err_handler = ip6gre_err,
94941 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
94942@@ -1617,7 +1617,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
94943 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
94944 };
94945
94946-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94947+static struct rtnl_link_ops ip6gre_link_ops = {
94948 .kind = "ip6gre",
94949 .maxtype = IFLA_GRE_MAX,
94950 .policy = ip6gre_policy,
94951@@ -1630,7 +1630,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94952 .fill_info = ip6gre_fill_info,
94953 };
94954
94955-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
94956+static struct rtnl_link_ops ip6gre_tap_ops = {
94957 .kind = "ip6gretap",
94958 .maxtype = IFLA_GRE_MAX,
94959 .policy = ip6gre_policy,
94960diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
94961index 1e55866..b398dab 100644
94962--- a/net/ipv6/ip6_tunnel.c
94963+++ b/net/ipv6/ip6_tunnel.c
94964@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
94965
94966 static int ip6_tnl_dev_init(struct net_device *dev);
94967 static void ip6_tnl_dev_setup(struct net_device *dev);
94968-static struct rtnl_link_ops ip6_link_ops __read_mostly;
94969+static struct rtnl_link_ops ip6_link_ops;
94970
94971 static int ip6_tnl_net_id __read_mostly;
94972 struct ip6_tnl_net {
94973@@ -1672,7 +1672,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
94974 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
94975 };
94976
94977-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
94978+static struct rtnl_link_ops ip6_link_ops = {
94979 .kind = "ip6tnl",
94980 .maxtype = IFLA_IPTUN_MAX,
94981 .policy = ip6_tnl_policy,
94982diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
94983index d1e2e8e..51c19ae 100644
94984--- a/net/ipv6/ipv6_sockglue.c
94985+++ b/net/ipv6/ipv6_sockglue.c
94986@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
94987 if (sk->sk_type != SOCK_STREAM)
94988 return -ENOPROTOOPT;
94989
94990- msg.msg_control = optval;
94991+ msg.msg_control = (void __force_kernel *)optval;
94992 msg.msg_controllen = len;
94993 msg.msg_flags = flags;
94994
94995diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
94996index 44400c2..8e11f52 100644
94997--- a/net/ipv6/netfilter/ip6_tables.c
94998+++ b/net/ipv6/netfilter/ip6_tables.c
94999@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
95000 #endif
95001
95002 static int get_info(struct net *net, void __user *user,
95003- const int *len, int compat)
95004+ int len, int compat)
95005 {
95006 char name[XT_TABLE_MAXNAMELEN];
95007 struct xt_table *t;
95008 int ret;
95009
95010- if (*len != sizeof(struct ip6t_getinfo)) {
95011- duprintf("length %u != %zu\n", *len,
95012+ if (len != sizeof(struct ip6t_getinfo)) {
95013+ duprintf("length %u != %zu\n", len,
95014 sizeof(struct ip6t_getinfo));
95015 return -EINVAL;
95016 }
95017@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
95018 info.size = private->size;
95019 strcpy(info.name, name);
95020
95021- if (copy_to_user(user, &info, *len) != 0)
95022+ if (copy_to_user(user, &info, len) != 0)
95023 ret = -EFAULT;
95024 else
95025 ret = 0;
95026@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95027
95028 switch (cmd) {
95029 case IP6T_SO_GET_INFO:
95030- ret = get_info(sock_net(sk), user, len, 1);
95031+ ret = get_info(sock_net(sk), user, *len, 1);
95032 break;
95033 case IP6T_SO_GET_ENTRIES:
95034 ret = compat_get_entries(sock_net(sk), user, len);
95035@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95036
95037 switch (cmd) {
95038 case IP6T_SO_GET_INFO:
95039- ret = get_info(sock_net(sk), user, len, 0);
95040+ ret = get_info(sock_net(sk), user, *len, 0);
95041 break;
95042
95043 case IP6T_SO_GET_ENTRIES:
95044diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
95045index dffdc1a..ccc6678 100644
95046--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
95047+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
95048@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
95049
95050 static int nf_ct_frag6_sysctl_register(struct net *net)
95051 {
95052- struct ctl_table *table;
95053+ ctl_table_no_const *table = NULL;
95054 struct ctl_table_header *hdr;
95055
95056- table = nf_ct_frag6_sysctl_table;
95057 if (!net_eq(net, &init_net)) {
95058- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
95059+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
95060 GFP_KERNEL);
95061 if (table == NULL)
95062 goto err_alloc;
95063@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95064 table[0].data = &net->nf_frag.frags.timeout;
95065 table[1].data = &net->nf_frag.frags.low_thresh;
95066 table[2].data = &net->nf_frag.frags.high_thresh;
95067- }
95068-
95069- hdr = register_net_sysctl(net, "net/netfilter", table);
95070+ hdr = register_net_sysctl(net, "net/netfilter", table);
95071+ } else
95072+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
95073 if (hdr == NULL)
95074 goto err_reg;
95075
95076@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
95077 return 0;
95078
95079 err_reg:
95080- if (!net_eq(net, &init_net))
95081- kfree(table);
95082+ kfree(table);
95083 err_alloc:
95084 return -ENOMEM;
95085 }
95086diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
95087index c2e73e6..12cca6f 100644
95088--- a/net/ipv6/output_core.c
95089+++ b/net/ipv6/output_core.c
95090@@ -8,8 +8,8 @@
95091
95092 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95093 {
95094- static atomic_t ipv6_fragmentation_id;
95095- int old, new;
95096+ static atomic_unchecked_t ipv6_fragmentation_id;
95097+ int id;
95098
95099 #if IS_ENABLED(CONFIG_IPV6)
95100 if (rt && !(rt->dst.flags & DST_NOPEER)) {
95101@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
95102 }
95103 }
95104 #endif
95105- do {
95106- old = atomic_read(&ipv6_fragmentation_id);
95107- new = old + 1;
95108- if (!new)
95109- new = 1;
95110- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
95111- fhdr->identification = htonl(new);
95112+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95113+ if (!id)
95114+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
95115+ fhdr->identification = htonl(id);
95116 }
95117 EXPORT_SYMBOL(ipv6_select_ident);
95118
95119diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
95120index eedff8c..7d7e24a 100644
95121--- a/net/ipv6/raw.c
95122+++ b/net/ipv6/raw.c
95123@@ -108,7 +108,7 @@ found:
95124 */
95125 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
95126 {
95127- struct icmp6hdr *_hdr;
95128+ struct icmp6hdr _hdr;
95129 const struct icmp6hdr *hdr;
95130
95131 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
95132@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
95133 {
95134 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
95135 skb_checksum_complete(skb)) {
95136- atomic_inc(&sk->sk_drops);
95137+ atomic_inc_unchecked(&sk->sk_drops);
95138 kfree_skb(skb);
95139 return NET_RX_DROP;
95140 }
95141@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95142 struct raw6_sock *rp = raw6_sk(sk);
95143
95144 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
95145- atomic_inc(&sk->sk_drops);
95146+ atomic_inc_unchecked(&sk->sk_drops);
95147 kfree_skb(skb);
95148 return NET_RX_DROP;
95149 }
95150@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
95151
95152 if (inet->hdrincl) {
95153 if (skb_checksum_complete(skb)) {
95154- atomic_inc(&sk->sk_drops);
95155+ atomic_inc_unchecked(&sk->sk_drops);
95156 kfree_skb(skb);
95157 return NET_RX_DROP;
95158 }
95159@@ -602,7 +602,7 @@ out:
95160 return err;
95161 }
95162
95163-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
95164+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
95165 struct flowi6 *fl6, struct dst_entry **dstp,
95166 unsigned int flags)
95167 {
95168@@ -914,12 +914,15 @@ do_confirm:
95169 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
95170 char __user *optval, int optlen)
95171 {
95172+ struct icmp6_filter filter;
95173+
95174 switch (optname) {
95175 case ICMPV6_FILTER:
95176 if (optlen > sizeof(struct icmp6_filter))
95177 optlen = sizeof(struct icmp6_filter);
95178- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
95179+ if (copy_from_user(&filter, optval, optlen))
95180 return -EFAULT;
95181+ raw6_sk(sk)->filter = filter;
95182 return 0;
95183 default:
95184 return -ENOPROTOOPT;
95185@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95186 char __user *optval, int __user *optlen)
95187 {
95188 int len;
95189+ struct icmp6_filter filter;
95190
95191 switch (optname) {
95192 case ICMPV6_FILTER:
95193@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
95194 len = sizeof(struct icmp6_filter);
95195 if (put_user(len, optlen))
95196 return -EFAULT;
95197- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
95198+ filter = raw6_sk(sk)->filter;
95199+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
95200 return -EFAULT;
95201 return 0;
95202 default:
95203@@ -1251,7 +1256,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
95204 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
95205 0,
95206 sock_i_ino(sp),
95207- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
95208+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
95209 }
95210
95211 static int raw6_seq_show(struct seq_file *seq, void *v)
95212diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
95213index 790d9f4..68ae078 100644
95214--- a/net/ipv6/reassembly.c
95215+++ b/net/ipv6/reassembly.c
95216@@ -621,12 +621,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
95217
95218 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95219 {
95220- struct ctl_table *table;
95221+ ctl_table_no_const *table = NULL;
95222 struct ctl_table_header *hdr;
95223
95224- table = ip6_frags_ns_ctl_table;
95225 if (!net_eq(net, &init_net)) {
95226- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95227+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
95228 if (table == NULL)
95229 goto err_alloc;
95230
95231@@ -637,9 +636,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95232 /* Don't export sysctls to unprivileged users */
95233 if (net->user_ns != &init_user_ns)
95234 table[0].procname = NULL;
95235- }
95236+ hdr = register_net_sysctl(net, "net/ipv6", table);
95237+ } else
95238+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
95239
95240- hdr = register_net_sysctl(net, "net/ipv6", table);
95241 if (hdr == NULL)
95242 goto err_reg;
95243
95244@@ -647,8 +647,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
95245 return 0;
95246
95247 err_reg:
95248- if (!net_eq(net, &init_net))
95249- kfree(table);
95250+ kfree(table);
95251 err_alloc:
95252 return -ENOMEM;
95253 }
95254diff --git a/net/ipv6/route.c b/net/ipv6/route.c
95255index bacce6c..9d1741a 100644
95256--- a/net/ipv6/route.c
95257+++ b/net/ipv6/route.c
95258@@ -2903,7 +2903,7 @@ ctl_table ipv6_route_table_template[] = {
95259
95260 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
95261 {
95262- struct ctl_table *table;
95263+ ctl_table_no_const *table;
95264
95265 table = kmemdup(ipv6_route_table_template,
95266 sizeof(ipv6_route_table_template),
95267diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
95268index 60df36d..f3ab7c8 100644
95269--- a/net/ipv6/sit.c
95270+++ b/net/ipv6/sit.c
95271@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
95272 static void ipip6_dev_free(struct net_device *dev);
95273 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
95274 __be32 *v4dst);
95275-static struct rtnl_link_ops sit_link_ops __read_mostly;
95276+static struct rtnl_link_ops sit_link_ops;
95277
95278 static int sit_net_id __read_mostly;
95279 struct sit_net {
95280@@ -1453,7 +1453,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
95281 #endif
95282 };
95283
95284-static struct rtnl_link_ops sit_link_ops __read_mostly = {
95285+static struct rtnl_link_ops sit_link_ops = {
95286 .kind = "sit",
95287 .maxtype = IFLA_IPTUN_MAX,
95288 .policy = ipip6_policy,
95289diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
95290index e85c48b..b8268d3 100644
95291--- a/net/ipv6/sysctl_net_ipv6.c
95292+++ b/net/ipv6/sysctl_net_ipv6.c
95293@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
95294
95295 static int __net_init ipv6_sysctl_net_init(struct net *net)
95296 {
95297- struct ctl_table *ipv6_table;
95298+ ctl_table_no_const *ipv6_table;
95299 struct ctl_table *ipv6_route_table;
95300 struct ctl_table *ipv6_icmp_table;
95301 int err;
95302diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
95303index 0a17ed9..2526cc3 100644
95304--- a/net/ipv6/tcp_ipv6.c
95305+++ b/net/ipv6/tcp_ipv6.c
95306@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
95307 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
95308 }
95309
95310+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95311+extern int grsec_enable_blackhole;
95312+#endif
95313+
95314 static void tcp_v6_hash(struct sock *sk)
95315 {
95316 if (sk->sk_state != TCP_CLOSE) {
95317@@ -1398,6 +1402,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
95318 return 0;
95319
95320 reset:
95321+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95322+ if (!grsec_enable_blackhole)
95323+#endif
95324 tcp_v6_send_reset(sk, skb);
95325 discard:
95326 if (opt_skb)
95327@@ -1480,12 +1487,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
95328 TCP_SKB_CB(skb)->sacked = 0;
95329
95330 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
95331- if (!sk)
95332+ if (!sk) {
95333+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95334+ ret = 1;
95335+#endif
95336 goto no_tcp_socket;
95337+ }
95338
95339 process:
95340- if (sk->sk_state == TCP_TIME_WAIT)
95341+ if (sk->sk_state == TCP_TIME_WAIT) {
95342+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95343+ ret = 2;
95344+#endif
95345 goto do_time_wait;
95346+ }
95347
95348 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
95349 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
95350@@ -1536,6 +1551,10 @@ csum_error:
95351 bad_packet:
95352 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
95353 } else {
95354+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95355+ if (!grsec_enable_blackhole || (ret == 1 &&
95356+ (skb->dev->flags & IFF_LOOPBACK)))
95357+#endif
95358 tcp_v6_send_reset(NULL, skb);
95359 }
95360
95361diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
95362index e7b28f9..d09c290 100644
95363--- a/net/ipv6/udp.c
95364+++ b/net/ipv6/udp.c
95365@@ -52,6 +52,10 @@
95366 #include <trace/events/skb.h>
95367 #include "udp_impl.h"
95368
95369+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95370+extern int grsec_enable_blackhole;
95371+#endif
95372+
95373 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
95374 {
95375 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
95376@@ -419,7 +423,7 @@ try_again:
95377 if (unlikely(err)) {
95378 trace_kfree_skb(skb, udpv6_recvmsg);
95379 if (!peeked) {
95380- atomic_inc(&sk->sk_drops);
95381+ atomic_inc_unchecked(&sk->sk_drops);
95382 if (is_udp4)
95383 UDP_INC_STATS_USER(sock_net(sk),
95384 UDP_MIB_INERRORS,
95385@@ -665,7 +669,7 @@ csum_error:
95386 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
95387 drop:
95388 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
95389- atomic_inc(&sk->sk_drops);
95390+ atomic_inc_unchecked(&sk->sk_drops);
95391 kfree_skb(skb);
95392 return -1;
95393 }
95394@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
95395 if (likely(skb1 == NULL))
95396 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
95397 if (!skb1) {
95398- atomic_inc(&sk->sk_drops);
95399+ atomic_inc_unchecked(&sk->sk_drops);
95400 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
95401 IS_UDPLITE(sk));
95402 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
95403@@ -860,6 +864,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
95404 goto csum_error;
95405
95406 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
95407+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
95408+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
95409+#endif
95410 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
95411
95412 kfree_skb(skb);
95413@@ -1392,7 +1399,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
95414 0,
95415 sock_i_ino(sp),
95416 atomic_read(&sp->sk_refcnt), sp,
95417- atomic_read(&sp->sk_drops));
95418+ atomic_read_unchecked(&sp->sk_drops));
95419 }
95420
95421 int udp6_seq_show(struct seq_file *seq, void *v)
95422diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
95423index 23ed03d..465a71d 100644
95424--- a/net/ipv6/xfrm6_policy.c
95425+++ b/net/ipv6/xfrm6_policy.c
95426@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
95427
95428 static int __net_init xfrm6_net_init(struct net *net)
95429 {
95430- struct ctl_table *table;
95431+ ctl_table_no_const *table = NULL;
95432 struct ctl_table_header *hdr;
95433
95434- table = xfrm6_policy_table;
95435 if (!net_eq(net, &init_net)) {
95436- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95437+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
95438 if (!table)
95439 goto err_alloc;
95440
95441 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
95442- }
95443+ hdr = register_net_sysctl(net, "net/ipv6", table);
95444+ } else
95445+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
95446
95447- hdr = register_net_sysctl(net, "net/ipv6", table);
95448 if (!hdr)
95449 goto err_reg;
95450
95451@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
95452 return 0;
95453
95454 err_reg:
95455- if (!net_eq(net, &init_net))
95456- kfree(table);
95457+ kfree(table);
95458 err_alloc:
95459 return -ENOMEM;
95460 }
95461diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
95462index 41ac7938..75e3bb1 100644
95463--- a/net/irda/ircomm/ircomm_tty.c
95464+++ b/net/irda/ircomm/ircomm_tty.c
95465@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95466 add_wait_queue(&port->open_wait, &wait);
95467
95468 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
95469- __FILE__, __LINE__, tty->driver->name, port->count);
95470+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95471
95472 spin_lock_irqsave(&port->lock, flags);
95473 if (!tty_hung_up_p(filp))
95474- port->count--;
95475+ atomic_dec(&port->count);
95476 port->blocked_open++;
95477 spin_unlock_irqrestore(&port->lock, flags);
95478
95479@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95480 }
95481
95482 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
95483- __FILE__, __LINE__, tty->driver->name, port->count);
95484+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95485
95486 schedule();
95487 }
95488@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95489
95490 spin_lock_irqsave(&port->lock, flags);
95491 if (!tty_hung_up_p(filp))
95492- port->count++;
95493+ atomic_inc(&port->count);
95494 port->blocked_open--;
95495 spin_unlock_irqrestore(&port->lock, flags);
95496
95497 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
95498- __FILE__, __LINE__, tty->driver->name, port->count);
95499+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95500
95501 if (!retval)
95502 port->flags |= ASYNC_NORMAL_ACTIVE;
95503@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
95504
95505 /* ++ is not atomic, so this should be protected - Jean II */
95506 spin_lock_irqsave(&self->port.lock, flags);
95507- self->port.count++;
95508+ atomic_inc(&self->port.count);
95509 spin_unlock_irqrestore(&self->port.lock, flags);
95510 tty_port_tty_set(&self->port, tty);
95511
95512 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
95513- self->line, self->port.count);
95514+ self->line, atomic_read(&self->port.count));
95515
95516 /* Not really used by us, but lets do it anyway */
95517 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
95518@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
95519 tty_kref_put(port->tty);
95520 }
95521 port->tty = NULL;
95522- port->count = 0;
95523+ atomic_set(&port->count, 0);
95524 spin_unlock_irqrestore(&port->lock, flags);
95525
95526 wake_up_interruptible(&port->open_wait);
95527@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
95528 seq_putc(m, '\n');
95529
95530 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
95531- seq_printf(m, "Open count: %d\n", self->port.count);
95532+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
95533 seq_printf(m, "Max data size: %d\n", self->max_data_size);
95534 seq_printf(m, "Max header size: %d\n", self->max_header_size);
95535
95536diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
95537index ae69165..c8b82d8 100644
95538--- a/net/iucv/af_iucv.c
95539+++ b/net/iucv/af_iucv.c
95540@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
95541
95542 write_lock_bh(&iucv_sk_list.lock);
95543
95544- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
95545+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95546 while (__iucv_get_sock_by_name(name)) {
95547 sprintf(name, "%08x",
95548- atomic_inc_return(&iucv_sk_list.autobind_name));
95549+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95550 }
95551
95552 write_unlock_bh(&iucv_sk_list.lock);
95553diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
95554index 4fe76ff..426a904 100644
95555--- a/net/iucv/iucv.c
95556+++ b/net/iucv/iucv.c
95557@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
95558 return NOTIFY_OK;
95559 }
95560
95561-static struct notifier_block __refdata iucv_cpu_notifier = {
95562+static struct notifier_block iucv_cpu_notifier = {
95563 .notifier_call = iucv_cpu_notify,
95564 };
95565
95566diff --git a/net/key/af_key.c b/net/key/af_key.c
95567index ab8bd2c..cd2d641 100644
95568--- a/net/key/af_key.c
95569+++ b/net/key/af_key.c
95570@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
95571 static u32 get_acqseq(void)
95572 {
95573 u32 res;
95574- static atomic_t acqseq;
95575+ static atomic_unchecked_t acqseq;
95576
95577 do {
95578- res = atomic_inc_return(&acqseq);
95579+ res = atomic_inc_return_unchecked(&acqseq);
95580 } while (!res);
95581 return res;
95582 }
95583diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
95584index ae36f8e..09d42ac 100644
95585--- a/net/mac80211/cfg.c
95586+++ b/net/mac80211/cfg.c
95587@@ -806,7 +806,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
95588 ret = ieee80211_vif_use_channel(sdata, chandef,
95589 IEEE80211_CHANCTX_EXCLUSIVE);
95590 }
95591- } else if (local->open_count == local->monitors) {
95592+ } else if (local_read(&local->open_count) == local->monitors) {
95593 local->_oper_chandef = *chandef;
95594 ieee80211_hw_config(local, 0);
95595 }
95596@@ -2922,7 +2922,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
95597 else
95598 local->probe_req_reg--;
95599
95600- if (!local->open_count)
95601+ if (!local_read(&local->open_count))
95602 break;
95603
95604 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
95605@@ -3385,8 +3385,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
95606 if (chanctx_conf) {
95607 *chandef = chanctx_conf->def;
95608 ret = 0;
95609- } else if (local->open_count > 0 &&
95610- local->open_count == local->monitors &&
95611+ } else if (local_read(&local->open_count) > 0 &&
95612+ local_read(&local->open_count) == local->monitors &&
95613 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
95614 if (local->use_chanctx)
95615 *chandef = local->monitor_chandef;
95616diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
95617index 9ca8e32..48e4a9b 100644
95618--- a/net/mac80211/ieee80211_i.h
95619+++ b/net/mac80211/ieee80211_i.h
95620@@ -28,6 +28,7 @@
95621 #include <net/ieee80211_radiotap.h>
95622 #include <net/cfg80211.h>
95623 #include <net/mac80211.h>
95624+#include <asm/local.h>
95625 #include "key.h"
95626 #include "sta_info.h"
95627 #include "debug.h"
95628@@ -891,7 +892,7 @@ struct ieee80211_local {
95629 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
95630 spinlock_t queue_stop_reason_lock;
95631
95632- int open_count;
95633+ local_t open_count;
95634 int monitors, cooked_mntrs;
95635 /* number of interfaces with corresponding FIF_ flags */
95636 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
95637diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
95638index 514e90f..56f22bf 100644
95639--- a/net/mac80211/iface.c
95640+++ b/net/mac80211/iface.c
95641@@ -502,7 +502,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95642 break;
95643 }
95644
95645- if (local->open_count == 0) {
95646+ if (local_read(&local->open_count) == 0) {
95647 res = drv_start(local);
95648 if (res)
95649 goto err_del_bss;
95650@@ -545,7 +545,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95651 break;
95652 }
95653
95654- if (local->monitors == 0 && local->open_count == 0) {
95655+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
95656 res = ieee80211_add_virtual_monitor(local);
95657 if (res)
95658 goto err_stop;
95659@@ -653,7 +653,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95660 atomic_inc(&local->iff_promiscs);
95661
95662 if (coming_up)
95663- local->open_count++;
95664+ local_inc(&local->open_count);
95665
95666 if (hw_reconf_flags)
95667 ieee80211_hw_config(local, hw_reconf_flags);
95668@@ -691,7 +691,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95669 err_del_interface:
95670 drv_remove_interface(local, sdata);
95671 err_stop:
95672- if (!local->open_count)
95673+ if (!local_read(&local->open_count))
95674 drv_stop(local);
95675 err_del_bss:
95676 sdata->bss = NULL;
95677@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95678 }
95679
95680 if (going_down)
95681- local->open_count--;
95682+ local_dec(&local->open_count);
95683
95684 switch (sdata->vif.type) {
95685 case NL80211_IFTYPE_AP_VLAN:
95686@@ -895,7 +895,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95687 }
95688 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
95689
95690- if (local->open_count == 0)
95691+ if (local_read(&local->open_count) == 0)
95692 ieee80211_clear_tx_pending(local);
95693
95694 /*
95695@@ -931,7 +931,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95696
95697 ieee80211_recalc_ps(local, -1);
95698
95699- if (local->open_count == 0) {
95700+ if (local_read(&local->open_count) == 0) {
95701 ieee80211_stop_device(local);
95702
95703 /* no reconfiguring after stop! */
95704@@ -942,7 +942,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95705 ieee80211_configure_filter(local);
95706 ieee80211_hw_config(local, hw_reconf_flags);
95707
95708- if (local->monitors == local->open_count)
95709+ if (local->monitors == local_read(&local->open_count))
95710 ieee80211_add_virtual_monitor(local);
95711 }
95712
95713diff --git a/net/mac80211/main.c b/net/mac80211/main.c
95714index 8a7bfc4..be07e86 100644
95715--- a/net/mac80211/main.c
95716+++ b/net/mac80211/main.c
95717@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
95718 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
95719 IEEE80211_CONF_CHANGE_POWER);
95720
95721- if (changed && local->open_count) {
95722+ if (changed && local_read(&local->open_count)) {
95723 ret = drv_config(local, changed);
95724 /*
95725 * Goal:
95726@@ -921,7 +921,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
95727 hw->queues = IEEE80211_MAX_QUEUES;
95728
95729 local->workqueue =
95730- alloc_ordered_workqueue(wiphy_name(local->hw.wiphy), 0);
95731+ alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
95732 if (!local->workqueue) {
95733 result = -ENOMEM;
95734 goto fail_workqueue;
95735diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
95736index 3401262..d5cd68d 100644
95737--- a/net/mac80211/pm.c
95738+++ b/net/mac80211/pm.c
95739@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95740 struct ieee80211_sub_if_data *sdata;
95741 struct sta_info *sta;
95742
95743- if (!local->open_count)
95744+ if (!local_read(&local->open_count))
95745 goto suspend;
95746
95747 ieee80211_scan_cancel(local);
95748@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95749 cancel_work_sync(&local->dynamic_ps_enable_work);
95750 del_timer_sync(&local->dynamic_ps_timer);
95751
95752- local->wowlan = wowlan && local->open_count;
95753+ local->wowlan = wowlan && local_read(&local->open_count);
95754 if (local->wowlan) {
95755 int err = drv_suspend(local, wowlan);
95756 if (err < 0) {
95757@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95758 WARN_ON(!list_empty(&local->chanctx_list));
95759
95760 /* stop hardware - this must stop RX */
95761- if (local->open_count)
95762+ if (local_read(&local->open_count))
95763 ieee80211_stop_device(local);
95764
95765 suspend:
95766diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
95767index a02bef3..f2f38dd 100644
95768--- a/net/mac80211/rate.c
95769+++ b/net/mac80211/rate.c
95770@@ -712,7 +712,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
95771
95772 ASSERT_RTNL();
95773
95774- if (local->open_count)
95775+ if (local_read(&local->open_count))
95776 return -EBUSY;
95777
95778 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
95779diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
95780index c97a065..ff61928 100644
95781--- a/net/mac80211/rc80211_pid_debugfs.c
95782+++ b/net/mac80211/rc80211_pid_debugfs.c
95783@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
95784
95785 spin_unlock_irqrestore(&events->lock, status);
95786
95787- if (copy_to_user(buf, pb, p))
95788+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
95789 return -EFAULT;
95790
95791 return p;
95792diff --git a/net/mac80211/util.c b/net/mac80211/util.c
95793index 72e6292..e6319eb 100644
95794--- a/net/mac80211/util.c
95795+++ b/net/mac80211/util.c
95796@@ -1472,7 +1472,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95797 }
95798 #endif
95799 /* everything else happens only if HW was up & running */
95800- if (!local->open_count)
95801+ if (!local_read(&local->open_count))
95802 goto wake_up;
95803
95804 /*
95805@@ -1696,7 +1696,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95806 local->in_reconfig = false;
95807 barrier();
95808
95809- if (local->monitors == local->open_count && local->monitors > 0)
95810+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
95811 ieee80211_add_virtual_monitor(local);
95812
95813 /*
95814diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
95815index 56d22ca..87c778f 100644
95816--- a/net/netfilter/Kconfig
95817+++ b/net/netfilter/Kconfig
95818@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
95819
95820 To compile it as a module, choose M here. If unsure, say N.
95821
95822+config NETFILTER_XT_MATCH_GRADM
95823+ tristate '"gradm" match support'
95824+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
95825+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
95826+ ---help---
95827+ The gradm match allows to match on grsecurity RBAC being enabled.
95828+ It is useful when iptables rules are applied early on bootup to
95829+ prevent connections to the machine (except from a trusted host)
95830+ while the RBAC system is disabled.
95831+
95832 config NETFILTER_XT_MATCH_HASHLIMIT
95833 tristate '"hashlimit" match support'
95834 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
95835diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
95836index a1abf87..dbcb7ee 100644
95837--- a/net/netfilter/Makefile
95838+++ b/net/netfilter/Makefile
95839@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
95840 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
95841 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
95842 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
95843+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
95844 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
95845 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
95846 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
95847diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
95848index f771390..145b765 100644
95849--- a/net/netfilter/ipset/ip_set_core.c
95850+++ b/net/netfilter/ipset/ip_set_core.c
95851@@ -1820,7 +1820,7 @@ done:
95852 return ret;
95853 }
95854
95855-static struct nf_sockopt_ops so_set __read_mostly = {
95856+static struct nf_sockopt_ops so_set = {
95857 .pf = PF_INET,
95858 .get_optmin = SO_IP_SET,
95859 .get_optmax = SO_IP_SET + 1,
95860diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
95861index a083bda..da661c3 100644
95862--- a/net/netfilter/ipvs/ip_vs_conn.c
95863+++ b/net/netfilter/ipvs/ip_vs_conn.c
95864@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
95865 /* Increase the refcnt counter of the dest */
95866 ip_vs_dest_hold(dest);
95867
95868- conn_flags = atomic_read(&dest->conn_flags);
95869+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
95870 if (cp->protocol != IPPROTO_UDP)
95871 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
95872 flags = cp->flags;
95873@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
95874
95875 cp->control = NULL;
95876 atomic_set(&cp->n_control, 0);
95877- atomic_set(&cp->in_pkts, 0);
95878+ atomic_set_unchecked(&cp->in_pkts, 0);
95879
95880 cp->packet_xmit = NULL;
95881 cp->app = NULL;
95882@@ -1190,7 +1190,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
95883
95884 /* Don't drop the entry if its number of incoming packets is not
95885 located in [0, 8] */
95886- i = atomic_read(&cp->in_pkts);
95887+ i = atomic_read_unchecked(&cp->in_pkts);
95888 if (i > 8 || i < 0) return 0;
95889
95890 if (!todrop_rate[i]) return 0;
95891diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
95892index 23b8eb5..48a8959 100644
95893--- a/net/netfilter/ipvs/ip_vs_core.c
95894+++ b/net/netfilter/ipvs/ip_vs_core.c
95895@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
95896 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
95897 /* do not touch skb anymore */
95898
95899- atomic_inc(&cp->in_pkts);
95900+ atomic_inc_unchecked(&cp->in_pkts);
95901 ip_vs_conn_put(cp);
95902 return ret;
95903 }
95904@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
95905 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
95906 pkts = sysctl_sync_threshold(ipvs);
95907 else
95908- pkts = atomic_add_return(1, &cp->in_pkts);
95909+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95910
95911 if (ipvs->sync_state & IP_VS_STATE_MASTER)
95912 ip_vs_sync_conn(net, cp, pkts);
95913diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
95914index 9e6c2a0..28552e2 100644
95915--- a/net/netfilter/ipvs/ip_vs_ctl.c
95916+++ b/net/netfilter/ipvs/ip_vs_ctl.c
95917@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
95918 */
95919 ip_vs_rs_hash(ipvs, dest);
95920 }
95921- atomic_set(&dest->conn_flags, conn_flags);
95922+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
95923
95924 /* bind the service */
95925 if (!dest->svc) {
95926@@ -1657,7 +1657,7 @@ proc_do_sync_ports(ctl_table *table, int write,
95927 * align with netns init in ip_vs_control_net_init()
95928 */
95929
95930-static struct ctl_table vs_vars[] = {
95931+static ctl_table_no_const vs_vars[] __read_only = {
95932 {
95933 .procname = "amemthresh",
95934 .maxlen = sizeof(int),
95935@@ -2060,7 +2060,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95936 " %-7s %-6d %-10d %-10d\n",
95937 &dest->addr.in6,
95938 ntohs(dest->port),
95939- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95940+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95941 atomic_read(&dest->weight),
95942 atomic_read(&dest->activeconns),
95943 atomic_read(&dest->inactconns));
95944@@ -2071,7 +2071,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95945 "%-7s %-6d %-10d %-10d\n",
95946 ntohl(dest->addr.ip),
95947 ntohs(dest->port),
95948- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95949+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95950 atomic_read(&dest->weight),
95951 atomic_read(&dest->activeconns),
95952 atomic_read(&dest->inactconns));
95953@@ -2549,7 +2549,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
95954
95955 entry.addr = dest->addr.ip;
95956 entry.port = dest->port;
95957- entry.conn_flags = atomic_read(&dest->conn_flags);
95958+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
95959 entry.weight = atomic_read(&dest->weight);
95960 entry.u_threshold = dest->u_threshold;
95961 entry.l_threshold = dest->l_threshold;
95962@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
95963 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
95964 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
95965 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
95966- (atomic_read(&dest->conn_flags) &
95967+ (atomic_read_unchecked(&dest->conn_flags) &
95968 IP_VS_CONN_F_FWD_MASK)) ||
95969 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
95970 atomic_read(&dest->weight)) ||
95971@@ -3682,7 +3682,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
95972 {
95973 int idx;
95974 struct netns_ipvs *ipvs = net_ipvs(net);
95975- struct ctl_table *tbl;
95976+ ctl_table_no_const *tbl;
95977
95978 atomic_set(&ipvs->dropentry, 0);
95979 spin_lock_init(&ipvs->dropentry_lock);
95980diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
95981index 5ea26bd..c9bc65f 100644
95982--- a/net/netfilter/ipvs/ip_vs_lblc.c
95983+++ b/net/netfilter/ipvs/ip_vs_lblc.c
95984@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
95985 * IPVS LBLC sysctl table
95986 */
95987 #ifdef CONFIG_SYSCTL
95988-static ctl_table vs_vars_table[] = {
95989+static ctl_table_no_const vs_vars_table[] __read_only = {
95990 {
95991 .procname = "lblc_expiration",
95992 .data = NULL,
95993diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
95994index 50123c2..067c773 100644
95995--- a/net/netfilter/ipvs/ip_vs_lblcr.c
95996+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
95997@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
95998 * IPVS LBLCR sysctl table
95999 */
96000
96001-static ctl_table vs_vars_table[] = {
96002+static ctl_table_no_const vs_vars_table[] __read_only = {
96003 {
96004 .procname = "lblcr_expiration",
96005 .data = NULL,
96006diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
96007index f6046d9..4f10cfd 100644
96008--- a/net/netfilter/ipvs/ip_vs_sync.c
96009+++ b/net/netfilter/ipvs/ip_vs_sync.c
96010@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
96011 cp = cp->control;
96012 if (cp) {
96013 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96014- pkts = atomic_add_return(1, &cp->in_pkts);
96015+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96016 else
96017 pkts = sysctl_sync_threshold(ipvs);
96018 ip_vs_sync_conn(net, cp->control, pkts);
96019@@ -758,7 +758,7 @@ control:
96020 if (!cp)
96021 return;
96022 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
96023- pkts = atomic_add_return(1, &cp->in_pkts);
96024+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
96025 else
96026 pkts = sysctl_sync_threshold(ipvs);
96027 goto sloop;
96028@@ -882,7 +882,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
96029
96030 if (opt)
96031 memcpy(&cp->in_seq, opt, sizeof(*opt));
96032- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96033+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
96034 cp->state = state;
96035 cp->old_state = cp->state;
96036 /*
96037diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
96038index b75ff64..0c51bbe 100644
96039--- a/net/netfilter/ipvs/ip_vs_xmit.c
96040+++ b/net/netfilter/ipvs/ip_vs_xmit.c
96041@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
96042 else
96043 rc = NF_ACCEPT;
96044 /* do not touch skb anymore */
96045- atomic_inc(&cp->in_pkts);
96046+ atomic_inc_unchecked(&cp->in_pkts);
96047 goto out;
96048 }
96049
96050@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
96051 else
96052 rc = NF_ACCEPT;
96053 /* do not touch skb anymore */
96054- atomic_inc(&cp->in_pkts);
96055+ atomic_inc_unchecked(&cp->in_pkts);
96056 goto out;
96057 }
96058
96059diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
96060index 2d3030a..7ba1c0a 100644
96061--- a/net/netfilter/nf_conntrack_acct.c
96062+++ b/net/netfilter/nf_conntrack_acct.c
96063@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
96064 #ifdef CONFIG_SYSCTL
96065 static int nf_conntrack_acct_init_sysctl(struct net *net)
96066 {
96067- struct ctl_table *table;
96068+ ctl_table_no_const *table;
96069
96070 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
96071 GFP_KERNEL);
96072diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
96073index 0283bae..5febcb0 100644
96074--- a/net/netfilter/nf_conntrack_core.c
96075+++ b/net/netfilter/nf_conntrack_core.c
96076@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
96077 #define DYING_NULLS_VAL ((1<<30)+1)
96078 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
96079
96080+#ifdef CONFIG_GRKERNSEC_HIDESYM
96081+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
96082+#endif
96083+
96084 int nf_conntrack_init_net(struct net *net)
96085 {
96086 int ret;
96087@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
96088 goto err_stat;
96089 }
96090
96091+#ifdef CONFIG_GRKERNSEC_HIDESYM
96092+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
96093+#else
96094 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
96095+#endif
96096 if (!net->ct.slabname) {
96097 ret = -ENOMEM;
96098 goto err_slabname;
96099diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
96100index 1df1761..ce8b88a 100644
96101--- a/net/netfilter/nf_conntrack_ecache.c
96102+++ b/net/netfilter/nf_conntrack_ecache.c
96103@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
96104 #ifdef CONFIG_SYSCTL
96105 static int nf_conntrack_event_init_sysctl(struct net *net)
96106 {
96107- struct ctl_table *table;
96108+ ctl_table_no_const *table;
96109
96110 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
96111 GFP_KERNEL);
96112diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
96113index 974a2a4..52cc6ff 100644
96114--- a/net/netfilter/nf_conntrack_helper.c
96115+++ b/net/netfilter/nf_conntrack_helper.c
96116@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
96117
96118 static int nf_conntrack_helper_init_sysctl(struct net *net)
96119 {
96120- struct ctl_table *table;
96121+ ctl_table_no_const *table;
96122
96123 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
96124 GFP_KERNEL);
96125diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
96126index 0ab9636..cea3c6a 100644
96127--- a/net/netfilter/nf_conntrack_proto.c
96128+++ b/net/netfilter/nf_conntrack_proto.c
96129@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
96130
96131 static void
96132 nf_ct_unregister_sysctl(struct ctl_table_header **header,
96133- struct ctl_table **table,
96134+ ctl_table_no_const **table,
96135 unsigned int users)
96136 {
96137 if (users > 0)
96138diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
96139index a99b6c3..cb372f9 100644
96140--- a/net/netfilter/nf_conntrack_proto_dccp.c
96141+++ b/net/netfilter/nf_conntrack_proto_dccp.c
96142@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96143 const char *msg;
96144 u_int8_t state;
96145
96146- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96147+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96148 BUG_ON(dh == NULL);
96149
96150 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
96151@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
96152 out_invalid:
96153 if (LOG_INVALID(net, IPPROTO_DCCP))
96154 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
96155- NULL, msg);
96156+ NULL, "%s", msg);
96157 return false;
96158 }
96159
96160@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
96161 u_int8_t type, old_state, new_state;
96162 enum ct_dccp_roles role;
96163
96164- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96165+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96166 BUG_ON(dh == NULL);
96167 type = dh->dccph_type;
96168
96169@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96170 unsigned int cscov;
96171 const char *msg;
96172
96173- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
96174+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
96175 if (dh == NULL) {
96176 msg = "nf_ct_dccp: short packet ";
96177 goto out_invalid;
96178@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
96179
96180 out_invalid:
96181 if (LOG_INVALID(net, IPPROTO_DCCP))
96182- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
96183+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
96184 return -NF_ACCEPT;
96185 }
96186
96187diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
96188index 4d4d8f1..e0f9a32 100644
96189--- a/net/netfilter/nf_conntrack_proto_tcp.c
96190+++ b/net/netfilter/nf_conntrack_proto_tcp.c
96191@@ -526,7 +526,7 @@ static bool tcp_in_window(const struct nf_conn *ct,
96192 const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple;
96193 __u32 seq, ack, sack, end, win, swin;
96194 s16 receiver_offset;
96195- bool res;
96196+ bool res, in_recv_win;
96197
96198 /*
96199 * Get the required data from the packet.
96200@@ -649,14 +649,18 @@ static bool tcp_in_window(const struct nf_conn *ct,
96201 receiver->td_end, receiver->td_maxend, receiver->td_maxwin,
96202 receiver->td_scale);
96203
96204+ /* Is the ending sequence in the receive window (if available)? */
96205+ in_recv_win = !receiver->td_maxwin ||
96206+ after(end, sender->td_end - receiver->td_maxwin - 1);
96207+
96208 pr_debug("tcp_in_window: I=%i II=%i III=%i IV=%i\n",
96209 before(seq, sender->td_maxend + 1),
96210- after(end, sender->td_end - receiver->td_maxwin - 1),
96211+ (in_recv_win ? 1 : 0),
96212 before(sack, receiver->td_end + 1),
96213 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
96214
96215 if (before(seq, sender->td_maxend + 1) &&
96216- after(end, sender->td_end - receiver->td_maxwin - 1) &&
96217+ in_recv_win &&
96218 before(sack, receiver->td_end + 1) &&
96219 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
96220 /*
96221@@ -725,7 +729,7 @@ static bool tcp_in_window(const struct nf_conn *ct,
96222 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
96223 "nf_ct_tcp: %s ",
96224 before(seq, sender->td_maxend + 1) ?
96225- after(end, sender->td_end - receiver->td_maxwin - 1) ?
96226+ in_recv_win ?
96227 before(sack, receiver->td_end + 1) ?
96228 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1) ? "BUG"
96229 : "ACK is under the lower bound (possible overly delayed ACK)"
96230diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
96231index bd700b4..4a3dc61 100644
96232--- a/net/netfilter/nf_conntrack_standalone.c
96233+++ b/net/netfilter/nf_conntrack_standalone.c
96234@@ -471,7 +471,7 @@ static ctl_table nf_ct_netfilter_table[] = {
96235
96236 static int nf_conntrack_standalone_init_sysctl(struct net *net)
96237 {
96238- struct ctl_table *table;
96239+ ctl_table_no_const *table;
96240
96241 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
96242 GFP_KERNEL);
96243diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
96244index 902fb0a..87f7fdb 100644
96245--- a/net/netfilter/nf_conntrack_timestamp.c
96246+++ b/net/netfilter/nf_conntrack_timestamp.c
96247@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
96248 #ifdef CONFIG_SYSCTL
96249 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
96250 {
96251- struct ctl_table *table;
96252+ ctl_table_no_const *table;
96253
96254 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
96255 GFP_KERNEL);
96256diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
96257index 3b18dd1..f79e0ca 100644
96258--- a/net/netfilter/nf_log.c
96259+++ b/net/netfilter/nf_log.c
96260@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
96261
96262 #ifdef CONFIG_SYSCTL
96263 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
96264-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
96265+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
96266
96267 static int nf_log_proc_dostring(ctl_table *table, int write,
96268 void __user *buffer, size_t *lenp, loff_t *ppos)
96269@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
96270 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
96271 mutex_unlock(&nf_log_mutex);
96272 } else {
96273+ ctl_table_no_const nf_log_table = *table;
96274+
96275 mutex_lock(&nf_log_mutex);
96276 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
96277 lockdep_is_held(&nf_log_mutex));
96278 if (!logger)
96279- table->data = "NONE";
96280+ nf_log_table.data = "NONE";
96281 else
96282- table->data = logger->name;
96283- r = proc_dostring(table, write, buffer, lenp, ppos);
96284+ nf_log_table.data = logger->name;
96285+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
96286 mutex_unlock(&nf_log_mutex);
96287 }
96288
96289diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
96290index f042ae5..30ea486 100644
96291--- a/net/netfilter/nf_sockopt.c
96292+++ b/net/netfilter/nf_sockopt.c
96293@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
96294 }
96295 }
96296
96297- list_add(&reg->list, &nf_sockopts);
96298+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
96299 out:
96300 mutex_unlock(&nf_sockopt_mutex);
96301 return ret;
96302@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
96303 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
96304 {
96305 mutex_lock(&nf_sockopt_mutex);
96306- list_del(&reg->list);
96307+ pax_list_del((struct list_head *)&reg->list);
96308 mutex_unlock(&nf_sockopt_mutex);
96309 }
96310 EXPORT_SYMBOL(nf_unregister_sockopt);
96311diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
96312index 962e979..e46f350 100644
96313--- a/net/netfilter/nfnetlink_log.c
96314+++ b/net/netfilter/nfnetlink_log.c
96315@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
96316 struct nfnl_log_net {
96317 spinlock_t instances_lock;
96318 struct hlist_head instance_table[INSTANCE_BUCKETS];
96319- atomic_t global_seq;
96320+ atomic_unchecked_t global_seq;
96321 };
96322
96323 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
96324@@ -419,6 +419,7 @@ __build_packet_message(struct nfnl_log_net *log,
96325 nfmsg->version = NFNETLINK_V0;
96326 nfmsg->res_id = htons(inst->group_num);
96327
96328+ memset(&pmsg, 0, sizeof(pmsg));
96329 pmsg.hw_protocol = skb->protocol;
96330 pmsg.hook = hooknum;
96331
96332@@ -498,7 +499,10 @@ __build_packet_message(struct nfnl_log_net *log,
96333 if (indev && skb->dev &&
96334 skb->mac_header != skb->network_header) {
96335 struct nfulnl_msg_packet_hw phw;
96336- int len = dev_parse_header(skb, phw.hw_addr);
96337+ int len;
96338+
96339+ memset(&phw, 0, sizeof(phw));
96340+ len = dev_parse_header(skb, phw.hw_addr);
96341 if (len > 0) {
96342 phw.hw_addrlen = htons(len);
96343 if (nla_put(inst->skb, NFULA_HWADDR, sizeof(phw), &phw))
96344@@ -559,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
96345 /* global sequence number */
96346 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
96347 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
96348- htonl(atomic_inc_return(&log->global_seq))))
96349+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
96350 goto nla_put_failure;
96351
96352 if (data_len) {
96353diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
96354index 5352b2d..e0083ce 100644
96355--- a/net/netfilter/nfnetlink_queue_core.c
96356+++ b/net/netfilter/nfnetlink_queue_core.c
96357@@ -444,7 +444,10 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
96358 if (indev && entskb->dev &&
96359 entskb->mac_header != entskb->network_header) {
96360 struct nfqnl_msg_packet_hw phw;
96361- int len = dev_parse_header(entskb, phw.hw_addr);
96362+ int len;
96363+
96364+ memset(&phw, 0, sizeof(phw));
96365+ len = dev_parse_header(entskb, phw.hw_addr);
96366 if (len) {
96367 phw.hw_addrlen = htons(len);
96368 if (nla_put(skb, NFQA_HWADDR, sizeof(phw), &phw))
96369diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
96370index 7011c71..6113cc7 100644
96371--- a/net/netfilter/xt_TCPMSS.c
96372+++ b/net/netfilter/xt_TCPMSS.c
96373@@ -52,7 +52,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96374 {
96375 const struct xt_tcpmss_info *info = par->targinfo;
96376 struct tcphdr *tcph;
96377- unsigned int tcplen, i;
96378+ int len, tcp_hdrlen;
96379+ unsigned int i;
96380 __be16 oldval;
96381 u16 newmss;
96382 u8 *opt;
96383@@ -64,11 +65,14 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96384 if (!skb_make_writable(skb, skb->len))
96385 return -1;
96386
96387- tcplen = skb->len - tcphoff;
96388+ len = skb->len - tcphoff;
96389+ if (len < (int)sizeof(struct tcphdr))
96390+ return -1;
96391+
96392 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
96393+ tcp_hdrlen = tcph->doff * 4;
96394
96395- /* Header cannot be larger than the packet */
96396- if (tcplen < tcph->doff*4)
96397+ if (len < tcp_hdrlen)
96398 return -1;
96399
96400 if (info->mss == XT_TCPMSS_CLAMP_PMTU) {
96401@@ -87,9 +91,8 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96402 newmss = info->mss;
96403
96404 opt = (u_int8_t *)tcph;
96405- for (i = sizeof(struct tcphdr); i < tcph->doff*4; i += optlen(opt, i)) {
96406- if (opt[i] == TCPOPT_MSS && tcph->doff*4 - i >= TCPOLEN_MSS &&
96407- opt[i+1] == TCPOLEN_MSS) {
96408+ for (i = sizeof(struct tcphdr); i <= tcp_hdrlen - TCPOLEN_MSS; i += optlen(opt, i)) {
96409+ if (opt[i] == TCPOPT_MSS && opt[i+1] == TCPOLEN_MSS) {
96410 u_int16_t oldmss;
96411
96412 oldmss = (opt[i+2] << 8) | opt[i+3];
96413@@ -112,9 +115,10 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96414 }
96415
96416 /* There is data after the header so the option can't be added
96417- without moving it, and doing so may make the SYN packet
96418- itself too large. Accept the packet unmodified instead. */
96419- if (tcplen > tcph->doff*4)
96420+ * without moving it, and doing so may make the SYN packet
96421+ * itself too large. Accept the packet unmodified instead.
96422+ */
96423+ if (len > tcp_hdrlen)
96424 return 0;
96425
96426 /*
96427@@ -143,10 +147,10 @@ tcpmss_mangle_packet(struct sk_buff *skb,
96428 newmss = min(newmss, (u16)1220);
96429
96430 opt = (u_int8_t *)tcph + sizeof(struct tcphdr);
96431- memmove(opt + TCPOLEN_MSS, opt, tcplen - sizeof(struct tcphdr));
96432+ memmove(opt + TCPOLEN_MSS, opt, len - sizeof(struct tcphdr));
96433
96434 inet_proto_csum_replace2(&tcph->check, skb,
96435- htons(tcplen), htons(tcplen + TCPOLEN_MSS), 1);
96436+ htons(len), htons(len + TCPOLEN_MSS), 1);
96437 opt[0] = TCPOPT_MSS;
96438 opt[1] = TCPOLEN_MSS;
96439 opt[2] = (newmss & 0xff00) >> 8;
96440diff --git a/net/netfilter/xt_TCPOPTSTRIP.c b/net/netfilter/xt_TCPOPTSTRIP.c
96441index b68fa19..625fa1d 100644
96442--- a/net/netfilter/xt_TCPOPTSTRIP.c
96443+++ b/net/netfilter/xt_TCPOPTSTRIP.c
96444@@ -38,7 +38,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
96445 struct tcphdr *tcph;
96446 u_int16_t n, o;
96447 u_int8_t *opt;
96448- int len;
96449+ int len, tcp_hdrlen;
96450
96451 /* This is a fragment, no TCP header is available */
96452 if (par->fragoff != 0)
96453@@ -52,7 +52,9 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
96454 return NF_DROP;
96455
96456 tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
96457- if (tcph->doff * 4 > len)
96458+ tcp_hdrlen = tcph->doff * 4;
96459+
96460+ if (len < tcp_hdrlen)
96461 return NF_DROP;
96462
96463 opt = (u_int8_t *)tcph;
96464@@ -61,10 +63,10 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
96465 * Walk through all TCP options - if we find some option to remove,
96466 * set all octets to %TCPOPT_NOP and adjust checksum.
96467 */
96468- for (i = sizeof(struct tcphdr); i < tcp_hdrlen(skb); i += optl) {
96469+ for (i = sizeof(struct tcphdr); i < tcp_hdrlen - 1; i += optl) {
96470 optl = optlen(opt, i);
96471
96472- if (i + optl > tcp_hdrlen(skb))
96473+ if (i + optl > tcp_hdrlen)
96474 break;
96475
96476 if (!tcpoptstrip_test_bit(info->strip_bmap, opt[i]))
96477diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
96478new file mode 100644
96479index 0000000..c566332
96480--- /dev/null
96481+++ b/net/netfilter/xt_gradm.c
96482@@ -0,0 +1,51 @@
96483+/*
96484+ * gradm match for netfilter
96485